You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

jwt.js 701B

123456789101112131415161718192021222324
  1. 'use strict'
  2. const JWT = require('jsonwebtoken')
  3. module.exports = options => {
  4. return {
  5. key: options.jwtKey,
  6. verifyOptions: {
  7. algorithms: ['HS256'],
  8. },
  9. validate: (decoded, request, h) => {
  10. const token = request.headers.authorization
  11. try {
  12. const validatedJwt = JWT.verify(token, process.env.APP_SECRET)
  13. return {
  14. isValid: true,
  15. credentials: validatedJwt.payload.email,
  16. }
  17. } catch (err) {
  18. console.error('ERROR :=>', err)
  19. return { isValid: false, error: err.message }
  20. }
  21. },
  22. }
  23. }