sdk/effect/lib/jwt-generator
Esta página aún no está disponible en tu idioma.
Interfaces
Section titled “Interfaces”JwtVerificationResult
Section titled “JwtVerificationResult”Defined in: studiocms/packages/studiocms/src/sdk/effect/lib/jwt-generator.ts:47^
Represents the result of verifying a JWT (JSON Web Token).
Properties
Section titled “Properties”isValid
Section titled “isValid”isValid: boolean;
Defined in: studiocms/packages/studiocms/src/sdk/effect/lib/jwt-generator.ts:48^
Indicates whether the JWT is valid.
userId?
Section titled “userId?”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.
Functions
Section titled “Functions”generateJwt()
Section titled “generateJwt()”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
.
Parameters
Section titled “Parameters”secret
Section titled “secret”string
The secret key used to sign the JWT.
payload
Section titled “payload”An object containing the JWT payload. Must include a userId
.
userId
Section titled “userId”string
noExpire?
Section titled “noExpire?”boolean
If true
, sets the token expiration to 30 years from now; otherwise, 24 hours.
Returns
Section titled “Returns”string
The generated JWT as a string.
verifyJwt()
Section titled “verifyJwt()”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.
Parameters
Section titled “Parameters”string
The JWT token string to verify.
secret
Section titled “secret”string
The secret key used to verify the token’s signature.
Returns
Section titled “Returns”An object indicating whether the token is valid and, if valid, the user ID.