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.
secretKeymust be at least 32 characters for security.userIdKeyspecifies the claim key for user ID.const
Properties
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