trySign method

String? trySign(
  1. JWTKey key, {
  2. JWTAlgorithm algorithm = JWTAlgorithm.HS256,
  3. Duration? expiresIn,
  4. Duration? notBefore,
  5. bool noIssueAt = false,
})

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

Implementation

String? trySign(
  JWTKey key, {
  JWTAlgorithm algorithm = JWTAlgorithm.HS256,
  Duration? expiresIn,
  Duration? notBefore,
  bool noIssueAt = false,
}) {
  try {
    return sign(
      key,
      algorithm: algorithm,
      expiresIn: expiresIn,
      notBefore: notBefore,
      noIssueAt: noIssueAt,
    );
  } catch (ex) {
    return null;
  }
}