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 errors.

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;
  }
}