tryVerify static method

JWT? tryVerify(
  1. String token,
  2. JWTKey key, {
  3. bool checkHeaderType = true,
  4. bool checkExpiresIn = true,
  5. bool checkNotBefore = true,
  6. Duration? issueAt,
  7. Audience? audience,
  8. String? subject,
  9. String? issuer,
  10. String? jwtId,
})

Exactly like verify, just return null instead of throwing exceptions.

Implementation

static JWT? tryVerify(
  String token,
  JWTKey key, {
  bool checkHeaderType = true,
  bool checkExpiresIn = true,
  bool checkNotBefore = true,
  Duration? issueAt,
  Audience? audience,
  String? subject,
  String? issuer,
  String? jwtId,
}) {
  try {
    return verify(
      token,
      key,
      checkHeaderType: checkHeaderType,
      checkExpiresIn: checkExpiresIn,
      checkNotBefore: checkNotBefore,
      issueAt: issueAt,
      audience: audience,
      subject: subject,
      issuer: issuer,
      jwtId: jwtId,
    );
  } catch (ex) {
    return null;
  }
}