jsonwebtoken#TokenExpiredError TypeScript Examples

The following examples show how to use jsonwebtoken#TokenExpiredError. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: Token.ts    From expresso with MIT License 6 votes vote down vote up
/**
 *
 * @param token
 * @returns
 */
function verifyAccessToken(token: string): DtoVerifyAccessToken {
  try {
    if (!token) {
      return { data: null, message: 'Unauthorized!' }
    }

    const data = jwt.verify(token, JWT_SECRET_ACCESS_TOKEN)
    return { data, message: 'Token is verify' }
  } catch (err) {
    if (err instanceof TokenExpiredError) {
      console.log(logErrServer('JWT Expired Error:', err.message))
      return { data: null, message: `JWT Expired Error: ${err.message}` }
    }

    if (err instanceof JsonWebTokenError) {
      console.log(logErrServer('JWT Token Error:', err.message))
      return { data: null, message: `JWT Token Error: ${err.message}` }
    }

    if (err instanceof NotBeforeError) {
      console.log(logErrServer('JWT Not Before Error:', err.message))
      return { data: null, message: `JWT Not Before Error: ${err.message}` }
    }
  }
}