Module

Token Utility

This module contains functions for generating and verifying JWT tokens.

View Source API/src/utils/token.js, line 1

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

View Source API/src/utils/token.js, line 245

  • 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

View Source API/src/utils/token.js, line 141

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

View Source API/src/utils/token.js, line 91

  • 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 token
  • refresh - Refresh token
  • password_reset - Password reset token
Parameters:
Name Type Description
type string

Type of token to generate

View Source API/src/utils/token.js, line 39

secret and expiry for the specified token type