Skip to content

Commit

Permalink
Make rexp optional
Browse files Browse the repository at this point in the history
  • Loading branch information
itaihanski committed Mar 12, 2024
1 parent 4cb0712 commit 9dc650d
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions lib/src/session/token.dart
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,8 @@ class Token implements DescopeToken {
final projectId = decoderIssuer(Claim.issuer.getTypedValue<String>(claims));
final expiration = Claim.expiration.getTypedValue<int>(claims);
final expiresAt = DateTime.fromMillisecondsSinceEpoch(expiration * 1000, isUtc: true);
final refreshExpiration = Claim.refreshExpiration.getTypedValue<String>(claims);
final refreshExpiresAt = refreshExpiration.isNotEmpty ? DateTime.parse(refreshExpiration) : null;
final refreshExpiration = Claim.refreshExpiration.getOptionalTypedValue<String>(claims);
final refreshExpiresAt = refreshExpiration != null && refreshExpiration.isNotEmpty ? DateTime.parse(refreshExpiration) : null;
final customClaims = claims.filterPrivateClaims();
return Token(jwt, id, projectId, expiresAt, refreshExpiresAt, customClaims, claims);
}
Expand Down Expand Up @@ -194,6 +194,14 @@ enum Claim {
return Claim.values.any((element) => element.key == key);
}

T? getOptionalTypedValue<T>(Map<String, dynamic> claims) {
try {
return getTypedValue<T>(claims);
} catch (e) {
return null;
}
}

T getTypedValue<T>(Map<String, dynamic> claims) {
final object = claims[key];
if (object == null) {
Expand Down

0 comments on commit 9dc650d

Please sign in to comment.