add support for token validation on login page
Some checks failed
Release / meta (push) Successful in 20s
Release / release-dev (push) Has been cancelled
Release / release-master (push) Has been cancelled
Release / android-build (push) Has been cancelled
Release / linux-build (push) Has been cancelled

This commit is contained in:
2025-12-14 12:15:39 +00:00
parent a2b38a7aec
commit 11a5a42ad4
4 changed files with 92 additions and 16 deletions

View File

@@ -72,8 +72,8 @@ class AuthService extends ChangeNotifier {
Future<void> tryRestoreSession() async {
if (_restoring || _user != null) return;
_restoring = true;
try {
_restoring = true;
try {
// read token from secure storage (with fallback)
final token = await _tokenStorage.getToken();
if (token == null || token.isEmpty) return;
@@ -100,6 +100,24 @@ class AuthService extends ChangeNotifier {
}
}
Future<bool> validateStoredToken() async {
final token = await _tokenStorage.getToken();
if (token == null || token.isEmpty) return false;
try {
await api.get(
'/validate',
headers: {
'Authorization': 'Bearer $token',
'accept': 'application/json',
},
);
return true;
} catch (_) {
await _clearToken();
return false;
}
}
Future<void> _persistToken(String token) async {
await _tokenStorage.setToken(token);
}