jwt
JWT (JSON Web Token) utility function for signing and verifying tokens using HS256 algorithm.
Source
Type Definition
function jwt(secret: string): {
  sign: (payload: Record<string, unknown>, options?: { expiresIn?: string | number | Date }) => Promise<string>
  verify: <T = unknown>(token: string) => Promise<T>
}Parameters
| Parameter | Type | Required | Default | Description | 
|---|---|---|---|---|
secret | string | ✅ | - | Secret key for signing and verifying tokens | 
Methods
sign
Signs a JWT token with the provided payload.
Parameters
| Parameter | Type | Required | Default | Description | 
|---|---|---|---|---|
payload | Record<string, unknown> | ✅ | - | Data to encode in the token | 
options | { expiresIn?: string | number | Date } | ❌ | - | Token expiration options | 
Returns
Promise<string>
verify
Verifies and decodes a JWT token.
Parameters
| Parameter | Type | Required | Default | Description | 
|---|---|---|---|---|
token | string | ✅ | - | JWT token to verify | 
Returns
Promise<T>
Last modified: 2025-06-10