Update: 2026-07-09 17:18:06
This commit is contained in:
@@ -5,7 +5,6 @@ import 'package:crypto/crypto.dart';
|
||||
import 'dart:math';
|
||||
import 'package:http/http.dart' as http;
|
||||
import 'package:permission_handler/permission_handler.dart';
|
||||
import 'package:siro_driver/views/auth/captin/cards/sms_signup.dart';
|
||||
import 'package:siro_driver/views/auth/syria/registration_view.dart';
|
||||
import 'package:siro_driver/views/widgets/elevated_btn.dart';
|
||||
import 'package:siro_driver/views/widgets/error_snakbar.dart';
|
||||
@@ -173,18 +172,23 @@ class LoginDriverController extends GetxController {
|
||||
if (parts.length == 3) {
|
||||
var payload = parts[1];
|
||||
switch (payload.length % 4) {
|
||||
case 2: payload += '=='; break;
|
||||
case 3: payload += '='; break;
|
||||
case 2:
|
||||
payload += '==';
|
||||
break;
|
||||
case 3:
|
||||
payload += '=';
|
||||
break;
|
||||
}
|
||||
final decoded = jsonDecode(utf8.decode(base64Url.decode(payload)));
|
||||
final exp = decoded['exp'];
|
||||
if (exp != null) {
|
||||
// Check if token has at least 10 seconds remaining
|
||||
isTokenValid = DateTime.now().millisecondsSinceEpoch < (exp * 1000 - 10000);
|
||||
isTokenValid =
|
||||
DateTime.now().millisecondsSinceEpoch < (exp * 1000 - 10000);
|
||||
}
|
||||
}
|
||||
} catch (_) {}
|
||||
|
||||
|
||||
if (isTokenValid) {
|
||||
Log.print('🔑 Valid Wallet JWT found in storage. Skipping generation.');
|
||||
return cachedJwt;
|
||||
@@ -226,7 +230,7 @@ class LoginDriverController extends GetxController {
|
||||
|
||||
getJWT() async {
|
||||
await EncryptionHelper.initialize();
|
||||
|
||||
|
||||
// 1. Check secure storage first to avoid redundant API calls
|
||||
String? secureJwt = await storage.read(key: BoxName.jwt);
|
||||
if (secureJwt != null && secureJwt.isNotEmpty) {
|
||||
@@ -236,18 +240,23 @@ class LoginDriverController extends GetxController {
|
||||
if (parts.length == 3) {
|
||||
String payload = parts[1];
|
||||
switch (payload.length % 4) {
|
||||
case 2: payload += '=='; break;
|
||||
case 3: payload += '='; break;
|
||||
case 2:
|
||||
payload += '==';
|
||||
break;
|
||||
case 3:
|
||||
payload += '=';
|
||||
break;
|
||||
}
|
||||
final decoded = jsonDecode(utf8.decode(base64Url.decode(payload)));
|
||||
final exp = decoded['exp'];
|
||||
if (exp != null) {
|
||||
// Check if token is valid with a 30-second buffer
|
||||
isTokenValid = DateTime.now().millisecondsSinceEpoch < (exp * 1000 - 30000);
|
||||
isTokenValid =
|
||||
DateTime.now().millisecondsSinceEpoch < (exp * 1000 - 30000);
|
||||
}
|
||||
}
|
||||
} catch (_) {}
|
||||
|
||||
|
||||
if (isTokenValid) {
|
||||
Log.print('🔑 Valid JWT found in secure storage. Skipping generation.');
|
||||
return;
|
||||
|
||||
Reference in New Issue
Block a user