akveo / akveo/ngx-admin

Login not redirecting in production mode

Open
#5,719 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
TypeScript
Stars
25.7k
Forks
7.9k
PR merge metrics
No merged PRs in 30d

Description

Hello. I have used the starter kit to develop my project. While in development mode using ng serve everything works fine. But when i use ng build --prod to build the app then the redirect after login stops working. My server use nodejs and it shows me the credentials received and the generated token sended back to my app. My app shows me the successful message but stays there. I'm publishing my app in a xampp server, and locally it works perfect, the problem is when I try to access from another PC from my LAN.
This is my code:

`export const NB_CORE_PROVIDERS = [
...MockDataModule.forRoot().providers,
...DATA_SERVICES,
...NbAuthModule.forRoot({

strategies: [
NbPasswordAuthStrategy.setup({
name: 'email',
token: {
class: NbAuthJWTToken,
key: 'token',
},
baseEndpoint: '',
login: {
// ...
endpoint: 'http://169.158.137.126:3000/user/login',
method: 'post',
redirect: {
success: '/',
failure: null,
},
},
logout: {
endpoint: '',
redirect: {
success: '/',
failure: null,
},
},
}),
],
forms: {
login: {
redirectDelay: 500, // delay before redirect after a successful login, while success message is shown to the user
strategy: 'email', // strategy id key.
rememberMe: false, // whether to show or not the `rememberMe` checkbox
showMessages: { // show/not show success/error messages
success: true,
error: true,
}, // social links at the bottom of a page
},
logout: {
redirectDelay: 500,
strategy: 'email',
},
},
}).providers,`

I don't know if the problem is my app o the xampp configuration. Any help?

Edit: I just tested it in another server, this time using node http-server and the problem persist. This is my authguard:
`
canActivate() {
return this.authService.isAuthenticated()
.pipe(
tap(authenticated => {
if (!authenticated) {
console.log('Redirecting to login...');
this.router.navigate(['auth/login']);
}
}),
);
}
`
I put the console.log and I notice that after the message showing that the credentials were correct, the app redirects again to the login page.

Edit2: The problems seems to be in the authService, I can see the token stored in the localstorage, and the login page sends me to my dashboard, but then my authguard sends me back to login page. This only happens in production build, while I'm in development mode using ng serve it works fine.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.