fix(auth): always redirect to phone login when unauthenticated
After logout or on app start with no/invalid token, the browser URL might be #/dashboard or #/auth/login. Using addPostFrameCallback to navigate to phoneLoginRoute once the navigator is ready ensures the user always lands on the phone login screen. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Sonnet 4.6
parent
13a99d4d34
commit
732da2e475
@@ -1,4 +1,5 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/scheduler.dart';
|
||||
import 'package:prosapp_web_app/models/usuario.dart';
|
||||
import 'package:prosapp_web_app/providers/professional_provider.dart';
|
||||
import 'package:prosapp_web_app/providers/services_provider.dart';
|
||||
@@ -170,6 +171,7 @@ class AuthProvider extends ChangeNotifier {
|
||||
if (token == null) {
|
||||
authStatus = AuthStatus.notAuthenticated;
|
||||
notifyListeners();
|
||||
_redirectToPhoneLogin();
|
||||
return false;
|
||||
}
|
||||
try {
|
||||
@@ -183,10 +185,17 @@ class AuthProvider extends ChangeNotifier {
|
||||
await _api.deleteToken();
|
||||
authStatus = AuthStatus.notAuthenticated;
|
||||
notifyListeners();
|
||||
_redirectToPhoneLogin();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
void _redirectToPhoneLogin() {
|
||||
SchedulerBinding.instance.addPostFrameCallback((_) {
|
||||
NavigationService.replaceTo(Flurorouter.phoneLoginRoute);
|
||||
});
|
||||
}
|
||||
|
||||
Future<void> logout() async {
|
||||
await _api.deleteToken();
|
||||
authStatus = AuthStatus.notAuthenticated;
|
||||
|
||||
Reference in New Issue
Block a user