Skip to content

Commit

Permalink
fix: isExpired() code comment, return false if token is valid instead…
Browse files Browse the repository at this point in the history
… of true
  • Loading branch information
debbsefe committed Jul 10, 2021
1 parent be9d65f commit 9437989
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions lib/jwt_decoder.dart
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class JwtDecoder {

/// Tells whether a token is expired.
///
/// Returns true if the token is valid, false if it is expired.
/// Returns false if the token is valid, true if it is expired.
///
/// Throws [FormatException] if parameter is not a valid JWT token.
static bool isExpired(String token) {
Expand All @@ -61,7 +61,8 @@ class JwtDecoder {
static DateTime getExpirationDate(String token) {
final decodedToken = decode(token);

final expirationDate = DateTime.fromMillisecondsSinceEpoch(0).add(Duration(seconds: decodedToken['exp'].toInt()));
final expirationDate = DateTime.fromMillisecondsSinceEpoch(0)
.add(Duration(seconds: decodedToken['exp'].toInt()));
return expirationDate;
}

Expand All @@ -71,7 +72,8 @@ class JwtDecoder {
static Duration getTokenTime(String token) {
final decodedToken = decode(token);

final issuedAtDate = DateTime.fromMillisecondsSinceEpoch(0).add(Duration(seconds: decodedToken["iat"]));
final issuedAtDate = DateTime.fromMillisecondsSinceEpoch(0)
.add(Duration(seconds: decodedToken["iat"]));
return DateTime.now().difference(issuedAtDate);
}

Expand Down

0 comments on commit 9437989

Please sign in to comment.