jwt
library
Functions
-
decode(String token)
→ List<Map<String, dynamic>>
-
Decodes
token without verifying the signature or validating claims.
-
jwt({required String secret, String alg = 'HS256', String? cookie, VerifyOptions? verifyOptions})
→ Middleware
-
JWT authentication middleware.
-
optionalJwt({required String secret, String alg = 'HS256', String? cookie, VerifyOptions? verifyOptions})
→ Middleware
-
Optional JWT middleware — never rejects the request.
-
sign(dynamic payload, String secret, {String alg = 'HS256'})
→ Future<String>
-
Signs
payload with secret and returns a compact JWT string.
-
verify(String token, String secret, [String alg = 'HS256'])
→ Future<Map<String, dynamic>>
-
Verifies
token against secret using alg, validates standard
time-based claims (exp, nbf, iat), and returns the decoded payload.
Exceptions / Errors
-
JwtException
-
Exception thrown when a JWT operation fails.