akveo / ngx-admin

Customizable admin dashboard template based on Angular 10+
https://akveo.github.io/ngx-admin/
MIT License
25.24k stars 7.95k forks source link

Issue with Nebular Authentication #1584

Open MrAnde7son opened 6 years ago

MrAnde7son commented 6 years ago

Issue type

Issue description

I recently added the nebular authentication module following the instructions. Using a dummy authentication provider, it worked as expected, unfortunately, after upgrading my node version to 8.9.4 (previously was 6.3) and npm to 5.6 (previously was 3.10). the authentication stopped working. When I type username&password, the page loads and fails to navigate to the home page (isAuthenticated returns false). While trying to debug the issue, I noticed the auth service returns a null token, and this is the reason why the authetication fails.

Related code:

auth-guard.service.ts

import { Injectable } from '@angular/core';
import { CanActivate, Router } from '@angular/router';
import { NbAuthService } from '@nebular/auth';
import { tap } from 'rxjs/operators/tap';

@Injectable()
export class AuthGuard implements CanActivate {

  constructor(private authService: NbAuthService, private router: Router) {
  }

  canActivate() {
    return this.authService.isAuthenticated()
      .pipe(
        tap(authenticated => {
          if (!authenticated) {
            this.router.navigate(['auth/login']);
          }
        }),
      );
  }
}

app.module.ts

...
NbAuthModule.forRoot({
      providers: {
        email: {
          service: NbDummyAuthProvider,
          config: {
            baseEndpoint: API_ADDRESS,
            login: {
              endpoint: '/auth/sign-in',
              method: 'post',
            },
            register: {
              endpoint: '/auth/sign-up',
              method: 'post',
            },
            logout: {
              endpoint: '/auth/sign-out',
              method: 'post',
            },
            requestPass: {
              endpoint: '/auth/request-pass',
              method: 'post',
            },
            resetPass: {
              endpoint: '/auth/reset-pass',
              method: 'post',
            },
            token: {
              key: 'token',
            },
          },
        },
      },
      forms: {
      },
    }),
...

package.json.txt

Am I missing something? Thanks in advance.

lucasfarruggia11 commented 4 years ago

Hi, I'm having the same problem, any solution?