This module contains functions for generating and verifying JWT tokens.
Requires
- module:../models/user.models
- module:../models/token.models
- module:../utils/errors
- module:jsonwebtoken
- module:../utils/config
- module:uuid
Methods
# inner decodeJWT(token) → {Object}
Decodes a JWT token
Parameters:
Name | Type | Description |
---|---|---|
token |
string
|
- Decoded token
Object
# async inner getAuthCodes(user_id, code_type)
Generate authentication codes for user, such as verification code, password reset code, activation code, deactivation code
Parameters:
Name | Type | Description |
---|---|---|
user_id |
ObjectId
|
|
code_type |
string
|
verification_code, password_reset_code,
activation_code1, activation_code2, activation_code3
# async inner getAuthTokens(user_id, token_type)
This function generates a JWT token for the specified user.
Parameters:
Name | Type | Default | Description |
---|---|---|---|
user_id |
ObjectId
|
ID of the user to generate token for |
|
token_type |
string
|
null | Type of token to generate |
- If user does not exist
NotFoundError
- If any other error occurs
Error
JWT token
# inner getRequiredConfigVars(type)
This function returns the secret and expiry for the specified token type.
The token type can be one of the following:
access
- Access tokenrefresh
- Refresh tokenpassword_reset
- Password reset token
Parameters:
Name | Type | Description |
---|---|---|
type |
string
|
Type of token to generate |
secret and expiry for the specified token type