You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
'use strict';constHapi=require('@hapi/hapi');constcrypto=require('crypto');constuser_routes=require("./routes/users");constproducts_routes=require("./routes/products");//const users = {};constall_routes=[user_routes,products_routes];constinit=async()=>{constserver=Hapi.server({port: 3000,host: 'localhost'});awaitserver.register(require('@hapi/cookie'));server.auth.strategy('session','cookie',{cookie: {name: 'session',password: crypto.randomBytes(32).toString('hex'),isSecure: false},validate: async(request,session)=>{//Validate function can't be called!!!constisValid=!!session.user;if(!isValid){throwBoom.unauthorized('You are not authorized to access this resource');}return{isValid: true,credentials: session};},});server.auth.default('session')server.ext('onPreResponse',(request,h)=>{constresponse=request.response;if(response){response.source={data: response.source,code: response.statusCode,message: response.isBoom ? (response.message||response.output.payload.message) : "success"};returnh.continue;}returnh.continue;});all_routes.forEach((item)=>{server.route(item);})awaitserver.start();console.log('Server running on \x1b[36m%s\x1b[0m',server.info.uri);};process.on('unhandledRejection',(err)=>{console.log(err);process.exit(1);});init();
exports.userLogin=async(request,h)=>{try{const{phone, password}=request.payload;constuser=awaitUsers.findOne({where:{
phone, password
}});if(user){request.cookieAuth.set({user:{name: user.name,phone: user.phone,userId: user.userId}});returnh.response(user);}else{returnBoom.unauthorized('Invalid user account or password')}}catch(error){h.response({error: `Internal server error:${error}`}).code(500);}}
The text was updated successfully, but these errors were encountered:
Runtime
nodejs v20.11.1
Runtime version
"@hapi/hapi": "^21.3.9"
Module version
"@hapi/cookie": "^12.0.1",
Used with
No response
Any other relevant information
"dependencies": {
"@hapi/cookie": "^12.0.1",
"@hapi/hapi": "^21.3.9",
"mysql2": "^3.9.7",
"sequelize": "^6.37.3",
"uuid": "^9.0.1"
}
How can we help?
The text was updated successfully, but these errors were encountered: