Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

role.provider not working in production mode #2544

Closed
RoWEN-FCUB opened this issue Oct 6, 2020 · 7 comments
Closed

role.provider not working in production mode #2544

RoWEN-FCUB opened this issue Oct 6, 2020 · 7 comments

Comments

@RoWEN-FCUB
Copy link

This is my role.provider.ts:

import { Injectable } from '@angular/core';
import { Observable } from 'rxjs/Observable';
import { map } from 'rxjs/operators/map';

import { NbAuthService, NbAuthJWTToken } from '@nebular/auth';
import { NbRoleProvider } from '@nebular/security';

@Injectable()
export class RoleProvider implements NbRoleProvider {

constructor(private authService: NbAuthService) {
}

getRole(): Observable {
return this.authService.onTokenChange()
.pipe(
map((token: NbAuthJWTToken) => {
// console.log(token.getPayload());
return token.isValid() ? token.getPayload()['role'] : 'guest';
}),
);
}
}

It works fine while in development mode (ng serve and ng build), but when I use it in production mode (ng serve --prod and ng build --prod) I get the error:

ERROR TypeError: Object(...) is not a function
getRole http://localhost:4200/main.c8da7df94aad960dcfeb.js:1
value http://localhost:4200/main.c8da7df94aad960dcfeb.js:1
set http://localhost:4200/main.c8da7df94aad960dcfeb.js:1
xa http://localhost:4200/main.c8da7df94aad960dcfeb.js:1
ra http://localhost:4200/main.c8da7df94aad960dcfeb.js:1
zs http://localhost:4200/main.c8da7df94aad960dcfeb.js:1
template http://localhost:4200/main.c8da7df94aad960dcfeb.js:1
Xi http://localhost:4200/main.c8da7df94aad960dcfeb.js:1
qi http://localhost:4200/main.c8da7df94aad960dcfeb.js:1
va http://localhost:4200/main.c8da7df94aad960dcfeb.js:1
qi http://localhost:4200/main.c8da7df94aad960dcfeb.js:1
qi http://localhost:4200/main.c8da7df94aad960dcfeb.js:1
va http://localhost:4200/main.c8da7df94aad960dcfeb.js:1
qi http://localhost:4200/main.c8da7df94aad960dcfeb.js:1
qi http://localhost:4200/main.c8da7df94aad960dcfeb.js:1
va http://localhost:4200/main.c8da7df94aad960dcfeb.js:1
qi http://localhost:4200/main.c8da7df94aad960dcfeb.js:1
qi http://localhost:4200/main.c8da7df94aad960dcfeb.js:1
qi http://localhost:4200/main.c8da7df94aad960dcfeb.js:1
qi http://localhost:4200/main.c8da7df94aad960dcfeb.js:1
va http://localhost:4200/main.c8da7df94aad960dcfeb.js:1
qi http://localhost:4200/main.c8da7df94aad960dcfeb.js:1
qi http://localhost:4200/main.c8da7df94aad960dcfeb.js:1
Gi http://localhost:4200/main.c8da7df94aad960dcfeb.js:1
_a http://localhost:4200/main.c8da7df94aad960dcfeb.js:1
a http://localhost:4200/main.c8da7df94aad960dcfeb.js:1
value http://localhost:4200/main.c8da7df94aad960dcfeb.js:1
value http://localhost:4200/main.c8da7df94aad960dcfeb.js:1
next http://localhost:4200/main.c8da7df94aad960dcfeb.js:1
value http://localhost:4200/polyfills.a9fe93f4256a69196a00.js:1
onInvoke http://localhost:4200/main.c8da7df94aad960dcfeb.js:1
value http://localhost:4200/polyfills.a9fe93f4256a69196a00.js:1
value http://localhost:4200/polyfills.a9fe93f4256a69196a00.js:1
value http://localhost:4200/main.c8da7df94aad960dcfeb.js:1
next http://localhost:4200/main.c8da7df94aad960dcfeb.js:1
o http://localhost:4200/main.c8da7df94aad960dcfeb.js:1
value http://localhost:4200/main.c8da7df94aad960dcfeb.js:1
value http://localhost:4200/main.c8da7df94aad960dcfeb.js:1
value http://localhost:4200/main.c8da7df94aad960dcfeb.js:1
value http://localhost:4200/main.c8da7df94aad960dcfeb.js:1
value http://localhost:4200/main.c8da7df94aad960dcfeb.js:1
value http://localhost:4200/main.c8da7df94aad960dcfeb.js:1
Vd http://localhost:4200/main.c8da7df94aad960dcfeb.js:1
onHasTask http://localhost:4200/main.c8da7df94aad960dcfeb.js:1
value http://localhost:4200/polyfills.a9fe93f4256a69196a00.js:1
value http://localhost:4200/polyfills.a9fe93f4256a69196a00.js:1
value http://localhost:4200/polyfills.a9fe93f4256a69196a00.js:1
value http://localhost:4200/polyfills.a9fe93f4256a69196a00.js:1
b http://localhost:4200/polyfills.a9fe93f4256a69196a00.js:1
promise callback*
http://localhost:4200/polyfills.a9fe93f4256a69196a00.js:1
value http://localhost:4200/polyfills.a9fe93f4256a69196a00.js:1
onScheduleTask http://localhost:4200/polyfills.a9fe93f4256a69196a00.js:1
value http://localhost:4200/polyfills.a9fe93f4256a69196a00.js:1
value http://localhost:4200/polyfills.a9fe93f4256a69196a00.js:1
value http://localhost:4200/polyfills.a9fe93f4256a69196a00.js:1
R http://localhost:4200/polyfills.a9fe93f4256a69196a00.js:1
P http://localhost:4200/polyfills.a9fe93f4256a69196a00.js:1
x http://localhost:4200/polyfills.a9fe93f4256a69196a00.js:1
r http://localhost:4200/runtime.1f7c745dcecd1542e20e.js:1
http://localhost:4200/5.c3b7e62258abfb184f47.js:1

@Prefix1802
Copy link
Contributor

Prefix1802 commented Oct 9, 2020

getRole(): Observable<string> {
    return this.authService.onTokenChange()
      .pipe(
        map((token: NbAuthJWTToken) => {
          return token.isValid() ? token.getPayload()['role'] : 'guest';
        }),
      );
  }

Observable string = missing.

@RoWEN-FCUB
Copy link
Author

import { Injectable } from '@angular/core';
import { Observable } from 'rxjs/Observable';
import { map } from 'rxjs/operators/map';

import { NbAuthService, NbAuthJWTToken } from '@nebular/auth';
import { NbRoleProvider } from '@nebular/security';

@Injectable()
export class RoleProvider implements NbRoleProvider {

  constructor(private authService: NbAuthService) {
  }

  getRole(): Observable<string> {
    return this.authService.onTokenChange()
      .pipe(
        map((token: NbAuthJWTToken) => {
          return token.isValid() ? token.getPayload()['role'] : 'guest';
        }),
      );
  }
}

Still having the same error. Only in production mode. All my modules are updates.
If I use:
useValue: { getRole: () => { return observableOf('user'); }
instead of useClass: RoleProvider it works fine, but I really need the role provider to work.
Sin título2

@RoWEN-FCUB
Copy link
Author

Can someone help me???? I'm still stuck with this error!!!

@bdowney01
Copy link

Are there any updates? I'm facing the same issue.

@RoWEN-FCUB
Copy link
Author

Still wating for an answer, tought I was the only with that problem.

@carloseduardovieira
Copy link

Hello @RoWEN-FCUB, I had this same problem, and the solution for me was to change the import path of the rxjs map..
change:
import { map } from 'rxjs/operators/map';
for
import { map } from 'rxjs/internal/operators/map';

@RoWEN-FCUB
Copy link
Author

Someone in another post gave me another solution and it's working now, this is my code:

import { Injectable } from '@angular/core';
import { Observable } from 'rxjs/Observable';
import { map } from 'rxjs/operators/map';

import { NbAuthService, NbAuthJWTToken } from '@nebular/auth';
import { NbRoleProvider } from '@nebular/security';
import { observable, of } from 'rxjs';

@Injectable()
export class RoleProvider implements NbRoleProvider {

  constructor(private authService: NbAuthService) {
  }

  getRole(): Observable<string> {
    /*return this.authService.onTokenChange()
      .pipe(
        map((token: NbAuthJWTToken) => {
          return token.isValid() ? token.getPayload()['role'] : 'guest';
        }),
      );*/
    let result;
    this.authService.onTokenChange().subscribe((token: NbAuthJWTToken) => {
      if (token.isValid()) {
        result = token.getPayload()['role'];
      } else {
        result = 'guest';
      }
    });
    // return observableOf(result);
    return of(result);
  }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants