Helper service for generating JWT.
JwtPrepareService
in NestJS is a service designed for generating JSON Web Tokens (JWTs) as part of the authentication process. This service simplifies the creation and management of JWTs.
JwtPrepareService
is prepareJwtResponse
, which generates JWTs based on user information and additional parameters:
userDocument
: The user’s document object from the database.withoutRefreshToken
: Optional flag to exclude a refresh token in the response.payload
: Additional data to include in the JWT.kind
: The type of account (e.g., INTERNAL, APPLE, GOOGLE). For UI purposes only.expiresIn
: Token expiry duration. Defaults to 20m
.jwtResponse
object is structured to include essential authentication details:
access_token
: The JWT for user authentication.refresh_token
: An optional token for refreshing the access token.user
: The user document containing user details.kind
can be conditionally included based on the arguments passed.userDocument
and any additional payload
.withoutRefreshToken
flag.JwtPrepareService
in a controller or service: