mirror of
https://github.com/SyncrowIOT/syncrow-app.git
synced 2025-11-27 21:44:54 +00:00
Bug fixes, and updated the build number
This commit is contained in:
@ -274,35 +274,39 @@ class AuthCubit extends Cubit<AuthState> {
|
||||
}
|
||||
|
||||
getTokenAndValidate() async {
|
||||
emit(AuthTokenLoading());
|
||||
const storage = FlutterSecureStorage();
|
||||
final firstLaunch =
|
||||
await SharedPreferencesHelper.readBoolFromSP(StringsManager.firstLaunch) ?? true;
|
||||
try {
|
||||
emit(AuthTokenLoading());
|
||||
const storage = FlutterSecureStorage();
|
||||
final firstLaunch =
|
||||
await SharedPreferencesHelper.readBoolFromSP(StringsManager.firstLaunch) ?? true;
|
||||
|
||||
if (firstLaunch) {
|
||||
storage.deleteAll();
|
||||
}
|
||||
|
||||
await SharedPreferencesHelper.saveBoolToSP(StringsManager.firstLaunch, false);
|
||||
|
||||
final value = await storage.read(key: Token.loginAccessTokenKey) ?? '';
|
||||
if (value.isEmpty) {
|
||||
emit(AuthTokenError(message: "Token not found"));
|
||||
return;
|
||||
}
|
||||
|
||||
final tokenData = Token.decodeToken(value);
|
||||
|
||||
if (tokenData.containsKey('exp')) {
|
||||
final exp = tokenData['exp'] ?? 0;
|
||||
final currentTime = DateTime.now().millisecondsSinceEpoch ~/ 1000;
|
||||
|
||||
if (currentTime < exp) {
|
||||
emit(AuthTokenSuccess());
|
||||
} else {
|
||||
emit(AuthTokenError(message: "Token expired"));
|
||||
if (firstLaunch) {
|
||||
storage.deleteAll();
|
||||
}
|
||||
} else {
|
||||
|
||||
await SharedPreferencesHelper.saveBoolToSP(StringsManager.firstLaunch, false);
|
||||
|
||||
final value = await storage.read(key: Token.loginAccessTokenKey) ?? '';
|
||||
if (value.isEmpty) {
|
||||
emit(AuthTokenError(message: "Token not found"));
|
||||
return;
|
||||
}
|
||||
|
||||
final tokenData = Token.decodeToken(value);
|
||||
|
||||
if (tokenData.containsKey('exp')) {
|
||||
final exp = tokenData['exp'] ?? 0;
|
||||
final currentTime = DateTime.now().millisecondsSinceEpoch ~/ 1000;
|
||||
|
||||
if (currentTime < exp) {
|
||||
emit(AuthTokenSuccess());
|
||||
} else {
|
||||
emit(AuthTokenError(message: "Token expired"));
|
||||
}
|
||||
} else {
|
||||
emit(AuthTokenError(message: "Something went wrong"));
|
||||
}
|
||||
} catch (_) {
|
||||
emit(AuthTokenError(message: "Something went wrong"));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user