0

this my routes code

const Joi = require('joi')
const handler = require('../handler/get-request')

const route = {
  method: 'POST',
  path: '/IB',
  options: {
    tags: ['api', 'IB', 'request'],
    description: 'Request New User IB',
    notes: 'It will return new user IB data',
    validate: {
      payload: {
        data: Joi.object().keys({
          cifNo: Joi.string().min(5).max(45).required(),
          userId: Joi.string().min(5).max(45).required(),
          deviceInfo: Joi.string().min(3).max(45).required()
        })
      }
    },
    plugins: {
      'hapi-swagger': {
        responses: {
          '200': {
            description: 'Success'
          }
        }
      }
    },
    auth: 'ib'
  },
  handler
}

module.exports = route

and this is my code where i registered the plugin hapi-auth-jwt

await server.register(require('hapi-auth-jwt2'))

    server.auth.strategy('ib', 'jwt', {
      key: config.internalServiceAccessToken,
      validate: async function (decoded, request) {
        // See https://github.com/dwyl/hapi-auth-jwt2
        // provides checking for invalidated token after user logout
        request.auth.decoded = decoded
        const user = await request.server.methods.services.ib.auth.findUser(decoded.username)
        
        return { isValid: user, credentials: decoded }
      },
      verifyOptions: { algorithms: ['RS256'] }
    })

when i hit my routes, i got this error message, "Error: Missing Authentication".

Can someone explain me why? and help me to fix this error. Big Thanks!

  • I am not familiar with hapi but are you sure that you are sending the token to client, storing it and then sending it back so the your backend can verify it? – Matus Dubrava Jul 22 '20 at 07:00
  • @MatusDubrava now i got an error 'invalid token' when i throw the jwt token into my headers of my routes. could you give me a solution? thanks btw for ur attention – Alif Pratama Jul 22 '20 at 10:38

0 Answers0