jwt
- Description:
- Provides methods for creating and verifying JSON Web Tokens (JWTs).
Methods
(static) create(payload, expiresInopt, optionsopt) → {string}
- Description:
- Creates a JSON Web Token (JWT) with the given payload and expiration.
Secret resolution:
options.secret→app.jsonjwt_secret/jwt.secret→gingee.jsonjwt.secret. Optionalissfrom options / app / server is set when configured.
- Creates a JSON Web Token (JWT) with the given payload and expiration.
Secret resolution:
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. |
options |
object |
<optional> |
Optional { secret, iss, expiresIn } (secret/iss may use env: / file: refs). |
Returns:
The JWT string.
- Type
- string
(static) verify(token, optionsopt) → {object|null}
- Description:
- Verifies a JWT and returns its payload if valid (signature + exp; iss when configured).
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 | Attributes | Description |
|---|---|---|---|
token |
string | The JWT string to verify. | |
options |
object |
<optional> |
Optional { secret, iss } overrides (may use env: / file: refs). |
Returns:
The token's payload if valid and not expired, otherwise null.
- Type
- object | null