util.jwtSign()
Signs a JWT.
Signature
static jwtSign(
payload: string | object,
secret: string | { key: string; passphrase: string },
options?: {
algorithm?:
| 'HS256'
| 'HS384'
| 'HS512'
| 'RS256'
| 'RS384'
| 'RS512'
| 'ES256'
| 'ES384'
| 'ES512'
| 'PS256'
| 'PS384'
| 'PS512'
| 'none';
keyid?: string;
expiresIn?: string | number;
notBefore?: string | number;
audience?: string | string[];
subject?: string;
issuer?: string;
jwtid?: string;
mutatePayload?: boolean;
noTimestamp?: boolean;
header?: JWTHeader;
encoding?: string;
allowInsecureKeySizes?: boolean;
allowInvalidAsymmetricKeyTypes?: boolean;
},
): string;
Example
const token = util.jwtSign(
{ sub: 'c-1' },
secret,
{ expiresIn: '1h' },
);

