The payload of the JWT.
Protected
parserReadonly
payloadThe payload of the JWT.
Gets the audience (aud
) claim of the JWT.
The "aud" (audience) claim identifies the recipients that the JWT is intended for. It can be a single string or an array of strings representing multiple audiences.
The audience claim or null if not present.
Gets the expiration time (exp
) of the JWT.
The "exp" (expiration time) claim defines the time after which the JWT must not be accepted. It is represented as a Unix timestamp in seconds.
The expiration timestamp or null if not set.
Sets the expiration time (exp
) of the JWT.
Specifies when the JWT will expire. After this time, the token is no longer valid.
The expiration timestamp to set.
Gets the expiration date as a Date
object.
Converts the expiration timestamp (exp
) into a Date
object.
The expiration date or null if not set.
Gets the JWT ID (jti
) claim.
The "jti" (JWT ID) claim is a unique identifier for the token. It is often used to prevent replay attacks by ensuring each JWT has a unique ID.
The JWT ID or null if not set.
Gets the issued-at (iat
) claim of the JWT.
The "iat" (issued at) claim represents the time at which the token was issued. It is typically used to track when the JWT was created.
The issuance date or null if not set.
Sets the issued-at (iat
) claim of the JWT.
Indicates the time the JWT was created.
The issuance date to set.
Gets the issuer (iss
) claim of the JWT.
The "iss" (issuer) claim identifies the entity that issued the JWT. This is typically a URL or identifier of the authentication server.
The issuer or null if not set.
Gets the not-before (nbf
) claim of the JWT.
The "nbf" (not before) claim specifies the earliest time at which the JWT is valid. The token should not be accepted before this time.
The not-before date or null if not set.
Sets the not-before (nbf
) claim of the JWT.
Defines when the JWT becomes valid.
The not-before date to set.
Gets the subject (sub
) claim of the JWT.
The "sub" (subject) claim represents the entity that the JWT is about. This is often the user ID or identifier of the authenticated entity.
The subject or null if not set.
Converts the Data
object into a plain JSON representation, including all
properties defined as getters in the subclass.
The toJSON
method dynamically identifies getter properties in the
subclass and collects their values to construct a JSON object. This is
particularly useful when you want to serialize the Data
object for APIs,
logging, or other use cases requiring JSON format.
A plain object representing the Data
instance with all getter properties.
class LoginData extends Data<FormParser> {
get username() {
return this.parser.getString("username");
}
get password() {
return this.parser.getString("password");
}
}
const loginData = new LoginData(new FormParser(formData));
console.log(JSON.stringify(loginData.toJSON()));
// Output: { "username": "johndoe", "password": "secret" }
Static
decodeStatic
signStatic
verify
Creates a new JWT instance with the given payload.