jwt

auth. Namespace

jwt

Description:
  • Provides methods for creating and verifying JSON Web Tokens (JWTs).

Methods

(static) create(payload, expiresInopt) → {string}

Description:
  • Creates a JSON Web Token (JWT) with the given payload and expiration.
Example
const token = auth.jwt.create({ userId: 42, role: 'admin' }, '2h');
Parameters:
Name Type Attributes Default Description
payload object The data to include in the token.
expiresIn string <optional>
'1h' The token's lifespan.
Returns:
The JWT string.
Type
string

(static) verify(token) → {object|null}

Description:
  • Verifies a JWT and returns its payload if valid.
Example
const payload = auth.jwt.verify(token);
if (payload) {
    console.log("Token is valid:", payload);
} else {
    console.log("Token is invalid or expired.");
}
Parameters:
Name Type Description
token string The JWT string to verify.
Returns:
The token's payload if valid and not expired, otherwise null.
Type
object | null