hapi-auth-jwt
hapi-auth-jwt copied to clipboard
Error: Auth is not defined after having updated the hapi package
Hello, I've upgraded an old Nodejs project to the latest Hapi version... I've read your documentation but I got this error when I start the Nodejs application...
Here's my code
const init = async () => {
const server = Hapi.server({
port: port,
host: 'localhost',
routes: { cors: { credentials: true } }
});
// include our module here ↓↓, for example, require('hapi-auth-jwt2')
await server.register(require('hapi-auth-jwt2'));
server.auth.strategy('jwt', 'jwt',
{
key: 'SECRETKEYIHAVE',
validateFunc: Auth.login_validate,
verifyOptions: { algorithms: ['HS256'] }// validate function defined above
});
server.auth.default('jwt');
server.route(routes);
await server.start();
logger.info('Server running on %s', server.info.uri);
return server;
};
process.on('unhandledRejection', (err) => {
logger.error(err.message);
process.exit(1);
});
init();
and here's my package.json
{
"name": "aaa-test",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
"dependencies": {
"boom": "^4.2.0",
"dotenv": "^8.2.0",
"@hapi/hapi": "^20.0.1",
"hapi-auth-jwt2": "^10.0.2",
"joi": "^10.2.0",
"minimist": "^1.2.0",
"mssql": "^3.3.0",
"request": "^2.81.0",
"tedious": "^1.14.0",
"winston": "^3.3.3",
"winston-daily-rotate-file": "^4.5.0",
"xmlbuilder": "^8.2.2",
"uuid": "^8.3.1",
"seq-logging": "^0.4.6"
}
}
Any suggestion? Thanks in advance