This commit is contained in:
parent
f8b1b8ad37
commit
e4f59dadfb
@ -62,7 +62,7 @@ class _MyAppState extends State<MyApp> {
|
||||
snackBarTheme: snackBarTheme,
|
||||
),
|
||||
title: constants.appTitle,
|
||||
initialRoute: '/',
|
||||
initialRoute: '/auth',
|
||||
routes: {
|
||||
'/':
|
||||
(context) =>
|
||||
@ -108,7 +108,14 @@ class AuthCheck extends StatelessWidget {
|
||||
return Consumer<Auth>(
|
||||
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<dynamic> route) => false);
|
||||
});
|
||||
return SizedBox.shrink();
|
||||
}
|
||||
|
||||
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
@ -14,7 +14,11 @@ class MountList with ChangeNotifier {
|
||||
final Auth _auth;
|
||||
|
||||
MountList(this._auth) {
|
||||
_fetch();
|
||||
_auth.addListener(() {
|
||||
if (_auth.authenticated) {
|
||||
_fetch();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
List<Mount> _mountList = [];
|
||||
@ -57,6 +61,7 @@ class MountList with ChangeNotifier {
|
||||
);
|
||||
|
||||
if (response.statusCode == 401) {
|
||||
displayAuthError();
|
||||
_auth.logoff();
|
||||
return;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user