Redirect not working after login
Closed this issue · 9 comments
I created a login form, after use authentication i need to redirect to home page, but redirect not work.
Here is my code:
`
exports.login = {
auth: {mode: 'try'},
handler: function(request, reply) {
User.find({email: request.payload.email}, (err, user) => {
if (err) {
return reply(Boom.badData('Internal MongoDB error', err));
}
if (user) {
if (Bcrypt.compareSync(request.payload.password, user[0].password)) {
request.cookieAuth.set(user);
console.log('Try redirect');
return reply.redirect('/');
}
}
reply.redirect('/login');
});
},
plugins: {
'hapi-auth-cookie': {
redirectTo: false
}
}
};
`
How are you authenticating on the client side ?
I only send via post the email and password, unsing angular.
$http.post(endpointURL + '/user/login', vm.user).success(function(data, status) { console.log('Usuário autenticado com sucesso.'); }).error(function(data, status) { alert('Ocorreu um erro: ' + data.message); });
An information, the user is registered, because if i type url manually, to index, it goes, but reply.redirect do nothing.
Here is my server strategy:
server.auth.strategy('session', 'cookie', true, { password: 'SessionAuth_Pé_Sword_Hapi_Server_Stats', //Use something more secure in production redirectTo: '/login', //If there is no session, redirect here ttl: 1 * 60 * 60 * 1000, // Set session to 1 day isSecure: false //Should be set to true (which is the default) in production });
It's an xhr request, it won't redirect your browser, that's your job.
You are right, In this case, How can I redirect ? Via front-end ?
That depends on your app I guess, using the $location service maybe ? My angular is a bit rusty.
Ok, thanks for your help, I saw that is a mistake by my side.
This thread has been automatically locked due to inactivity. Please open a new issue for related bugs or questions following the new issue template instructions.