This commit is contained in:
parent
f8b1b8ad37
commit
e4f59dadfb
@ -62,7 +62,7 @@ class _MyAppState extends State<MyApp> {
|
|||||||
snackBarTheme: snackBarTheme,
|
snackBarTheme: snackBarTheme,
|
||||||
),
|
),
|
||||||
title: constants.appTitle,
|
title: constants.appTitle,
|
||||||
initialRoute: '/',
|
initialRoute: '/auth',
|
||||||
routes: {
|
routes: {
|
||||||
'/':
|
'/':
|
||||||
(context) =>
|
(context) =>
|
||||||
@ -108,7 +108,14 @@ class AuthCheck extends StatelessWidget {
|
|||||||
return Consumer<Auth>(
|
return Consumer<Auth>(
|
||||||
builder: (context, auth, __) {
|
builder: (context, auth, __) {
|
||||||
if (!auth.authenticated) {
|
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();
|
return SizedBox.shrink();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -9,7 +9,7 @@ import 'package:sodium_libs/sodium_libs.dart';
|
|||||||
|
|
||||||
class Auth with ChangeNotifier {
|
class Auth with ChangeNotifier {
|
||||||
bool _authenticated = false;
|
bool _authenticated = false;
|
||||||
SecureKey _key = SecureKey.random(constants.sodium, 128);
|
SecureKey _key = SecureKey.random(constants.sodium, 32);
|
||||||
String _user = "";
|
String _user = "";
|
||||||
|
|
||||||
bool get authenticated => _authenticated;
|
bool get authenticated => _authenticated;
|
||||||
@ -53,6 +53,7 @@ class Auth with ChangeNotifier {
|
|||||||
void logoff() {
|
void logoff() {
|
||||||
_authenticated = false;
|
_authenticated = false;
|
||||||
_user = "";
|
_user = "";
|
||||||
|
|
||||||
notifyListeners();
|
notifyListeners();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -14,7 +14,11 @@ class MountList with ChangeNotifier {
|
|||||||
final Auth _auth;
|
final Auth _auth;
|
||||||
|
|
||||||
MountList(this._auth) {
|
MountList(this._auth) {
|
||||||
_fetch();
|
_auth.addListener(() {
|
||||||
|
if (_auth.authenticated) {
|
||||||
|
_fetch();
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
List<Mount> _mountList = [];
|
List<Mount> _mountList = [];
|
||||||
@ -57,6 +61,7 @@ class MountList with ChangeNotifier {
|
|||||||
);
|
);
|
||||||
|
|
||||||
if (response.statusCode == 401) {
|
if (response.statusCode == 401) {
|
||||||
|
displayAuthError();
|
||||||
_auth.logoff();
|
_auth.logoff();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user