Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Getting errors during registering hapi-auth-jwt2 while Using hapi.js 20 server #372

Open
abhilashdkadv opened this issue Oct 19, 2022 · 0 comments

Comments

@abhilashdkadv
Copy link

I am facing issues registering hapi-auth-jwt2 plugin in Hapi Server. We are upgrading from v16 to latest. Here is my register code:

const server = new Hapi.Server({
  host: '0.0.0.0',
  port: process.env.PORT
})
const start = async function () {

  await server.register({
      plugin: require('hapi-auth-jwt2'),
      options: {
        name: 'hapi-auth-jwt-2'
      }
  });
  server.auth.strategy('jwt', 'jwt',
    {
      key: Buffer.from(jwtSecret, 'base64'),
      validate: validate,
      verifyOptions: { algorithms: [ 'HS256' ] }
    })
    server.auth.default('jwt')
    server.route([//routes removed for clarity])
};  
start();
module.exports = () => {
  return server;
}

In another file we are importing and trying to start server

var server = require('./server')()
server.start().then(() => {})

But when I run I am getting "UnhandledPromiseRejectionWarning: Error: Cannot start server before plugins finished registration"

How to register hapi-auth-jwt2 successfully in the latest hapi version.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants