From e4f59dadfb4240ccf1ef6122b2630c3cf629a543 Mon Sep 17 00:00:00 2001 From: "Scott E. Graves" Date: Sat, 22 Mar 2025 02:20:03 -0500 Subject: [PATCH] refactoring --- web/repertory/lib/main.dart | 11 +++++++++-- web/repertory/lib/models/auth.dart | 3 ++- web/repertory/lib/models/mount_list.dart | 7 ++++++- 3 files changed, 17 insertions(+), 4 deletions(-) diff --git a/web/repertory/lib/main.dart b/web/repertory/lib/main.dart index afa61a73..93cac46f 100644 --- a/web/repertory/lib/main.dart +++ b/web/repertory/lib/main.dart @@ -62,7 +62,7 @@ class _MyAppState extends State { snackBarTheme: snackBarTheme, ), title: constants.appTitle, - initialRoute: '/', + initialRoute: '/auth', routes: { '/': (context) => @@ -108,7 +108,14 @@ class AuthCheck extends StatelessWidget { return Consumer( builder: (context, auth, __) { if (!auth.authenticated) { - Navigator.of(context).pushReplacementNamed('/auth'); + Future.delayed(Duration(milliseconds: 1), () { + if (constants.navigatorKey.currentContext == null) { + return; + } + Navigator.of( + constants.navigatorKey.currentContext!, + ).pushNamedAndRemoveUntil('/auth', (Route route) => false); + }); return SizedBox.shrink(); } diff --git a/web/repertory/lib/models/auth.dart b/web/repertory/lib/models/auth.dart index 614fd2eb..e9af0c6e 100644 --- a/web/repertory/lib/models/auth.dart +++ b/web/repertory/lib/models/auth.dart @@ -9,7 +9,7 @@ import 'package:sodium_libs/sodium_libs.dart'; class Auth with ChangeNotifier { bool _authenticated = false; - SecureKey _key = SecureKey.random(constants.sodium, 128); + SecureKey _key = SecureKey.random(constants.sodium, 32); String _user = ""; bool get authenticated => _authenticated; @@ -53,6 +53,7 @@ class Auth with ChangeNotifier { void logoff() { _authenticated = false; _user = ""; + notifyListeners(); } } diff --git a/web/repertory/lib/models/mount_list.dart b/web/repertory/lib/models/mount_list.dart index 508104ee..076de389 100644 --- a/web/repertory/lib/models/mount_list.dart +++ b/web/repertory/lib/models/mount_list.dart @@ -14,7 +14,11 @@ class MountList with ChangeNotifier { final Auth _auth; MountList(this._auth) { - _fetch(); + _auth.addListener(() { + if (_auth.authenticated) { + _fetch(); + } + }); } List _mountList = []; @@ -57,6 +61,7 @@ class MountList with ChangeNotifier { ); if (response.statusCode == 401) { + displayAuthError(); _auth.logoff(); return; }