T&C Finalized Test APK

This commit is contained in:
2025-11-10 13:24:52 +05:30
parent 5c8df8ace3
commit 078e715d20

View File

@@ -14,14 +14,24 @@ class AuthToken extends Equatable {
required this.tnc, required this.tnc,
}); });
factory AuthToken.fromJson(Map<String, dynamic> json) { factory AuthToken.fromJson(Map<String, dynamic> json) {
final token = json['token']; final token = json['token'];
return AuthToken(
accessToken: token, // Safely extract tnc.mobile directly from the outer JSON
expiresAt: _decodeExpiryFromToken(token), // Keep existing method for expiry bool tncMobileValue = false; // Default to false if not found or invalid
tnc: _decodeTncFromToken(token), // Use new method for tnc if (json.containsKey('tnc') && json['tnc'] is Map<String, dynamic>) {
); final tncMap = json['tnc'] as Map<String, dynamic>;
} if (tncMap.containsKey('mobile') && tncMap['mobile'] is bool) {
tncMobileValue = tncMap['mobile'] as bool;
}
}
return AuthToken(
accessToken: token,
expiresAt: _decodeExpiryFromToken(token), // This method is still valid for JWT expiry
tnc: tncMobileValue, // Use the correctly extracted value
);
}
static DateTime _decodeExpiryFromToken(String token) { static DateTime _decodeExpiryFromToken(String token) {
try { try {
@@ -46,42 +56,42 @@ class AuthToken extends Equatable {
} }
} }
static bool _decodeTncFromToken(String token) { // static bool _decodeTncFromToken(String token) {
try { // try {
final parts = token.split('.'); // final parts = token.split('.');
if (parts.length != 3) { // if (parts.length != 3) {
throw Exception('Invalid JWT format for TNC decoding'); // throw Exception('Invalid JWT format for TNC decoding');
} // }
final payload = parts[1]; // final payload = parts[1];
String normalized = base64Url.normalize(payload); // String normalized = base64Url.normalize(payload);
final payloadMap = json.decode(utf8.decode(base64Url.decode(normalized))); // final payloadMap = json.decode(utf8.decode(base64Url.decode(normalized)));
if (payloadMap is! Map<String, dynamic> || !payloadMap.containsKey('tnc')) { // if (payloadMap is! Map<String, dynamic> || !payloadMap.containsKey('tnc')) {
// If 'tnc' is not present in the payload, default to false // // If 'tnc' is not present in the payload, default to false
return false; // return false;
} // }
final tncValue = payloadMap['tnc']; // final tncValue = payloadMap['tnc'];
// Handle different representations of 'true' // // Handle different representations of 'true'
if (tncValue is bool) { // if (tncValue is bool) {
return tncValue; // return tncValue;
} // }
if (tncValue is String) { // if (tncValue is String) {
return tncValue.toLowerCase() == 'true'; // return tncValue.toLowerCase() == 'true';
} // }
if (tncValue is int) { // if (tncValue is int) {
return tncValue == 1; // return tncValue == 1;
} // }
// Default to false for any other case // // Default to false for any other case
return false; // return false;
} catch (e) { // } catch (e) {
log('Error decoding tnc from token: $e'); // log('Error decoding tnc from token: $e');
// Default to false if decoding fails or 'tnc' is not found/invalid // // Default to false if decoding fails or 'tnc' is not found/invalid
return false; // return false;
} // }
} // }
bool get isExpired => DateTime.now().isAfter(expiresAt); bool get isExpired => DateTime.now().isAfter(expiresAt);