add check token 25%

This commit is contained in:
2025-03-06 21:27:06 +01:00
parent 5c2a58e484
commit e7afe8fddb
7 changed files with 40 additions and 6 deletions

View File

@@ -3,6 +3,8 @@ import 'package:shared_preferences/shared_preferences.dart';
import 'package:http/http.dart' as http;
import '../variable/globals.dart' as globals;
import 'dart:io';
import 'package:flutter/material.dart';
import '../pages/LoginDemo.dart';
class AuthService {
// Login with username and password
@@ -86,6 +88,21 @@ class AuthService {
}
}
Future<void> checkTokenStatus(context) async {
bool loggedIn = await isLoggedIn();
SharedPreferences prefs = await SharedPreferences.getInstance();
if (!loggedIn) {
await prefs.remove("access_token"); // Correctly remove the token
Navigator.pushAndRemoveUntil(
context,
MaterialPageRoute(builder: (_) => LoginDemo()),
(route) => false, // Remove all previous routes
);
}
}
// Get stored access token
Future<String?> getAccessToken() async {
final prefs = await SharedPreferences.getInstance();