Saltearse al contenido

sdk/effect/lib/jwt-generator

Esta página aún no está disponible en tu idioma.

Defined in: studiocms/packages/studiocms/src/sdk/effect/lib/jwt-generator.ts:47^

Represents the result of verifying a JWT (JSON Web Token).

isValid: boolean;

Defined in: studiocms/packages/studiocms/src/sdk/effect/lib/jwt-generator.ts:48^

Indicates whether the JWT is valid.

optional userId: string;

Defined in: studiocms/packages/studiocms/src/sdk/effect/lib/jwt-generator.ts:49^

The user ID extracted from the token, if available. This is optional and may be undefined if the token is invalid.

function generateJwt(
secret: string,
payload: {
userId: string;
},
noExpire?: boolean): string

Defined in: studiocms/packages/studiocms/src/sdk/effect/lib/jwt-generator.ts:64^

Generates a JSON Web Token (JWT) using the provided secret and payload.

The token is signed using the HS256 algorithm. The payload must include a userId. The token’s expiration (exp) is set to 24 hours from the current time by default, or 30 years from today if noExpire is true.

string

The secret key used to sign the JWT.

An object containing the JWT payload. Must include a userId.

string

boolean

If true, sets the token expiration to 30 years from now; otherwise, 24 hours.

string

The generated JWT as a string.


function verifyJwt(token: string, secret: string): JwtVerificationResult

Defined in: studiocms/packages/studiocms/src/sdk/effect/lib/jwt-generator.ts:109^

Verifies a JWT token using the provided secret.

This function checks the token’s algorithm, expiration, and signature. It expects the token to use the HS256 algorithm and verifies the signature using HMAC SHA-256 with the provided secret concatenated with itself.

string

The JWT token string to verify.

string

The secret key used to verify the token’s signature.

JwtVerificationResult

An object indicating whether the token is valid and, if valid, the user ID.