JwtHandler class

Handles JWT token generation and validation. Supports both production JWT tokens and development auth tokens.

Constructors

JwtHandler({required String secretKey, required String devAuthToken, required bool isProd, required String userIdKey})
Creates a JwtHandler instance. secretKey must be at least 32 characters for security. userIdKey specifies the claim key for user ID.
const

Properties

devAuthToken String
final
hashCode int
The hash code for this object.
no setterinherited
isProd bool
final
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
secretKey String
final
userIdKey String
final

Methods

generateToken({Map<String, dynamic> claims = const {}, Duration maxAge = const Duration(hours: 1)}) String
Generates a JWT auth token with 1 hour expiration. Accepts custom claims.
getUserIdFromToken(String? token) → Result<int>
Extracts user ID from a JWT token. Returns Result<int> with user ID or error.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toString() String
A string representation of this object.
inherited
validateToken(String authToken) → Result<void>
Validates a JWT auth token. Returns Result<void> - success if valid, error if invalid.

Operators

operator ==(Object other) bool
The equality operator.
inherited