生产模式下Nebular NbRoleProvider的问题

时间:2020-10-06 16:37:04

标签: angular roleprovider nebular

这是我的角色。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<string> {
    return this.authService.onTokenChange()
      .pipe(
        map((token: NbAuthJWTToken) => {
          // console.log(token.getPayload());
          return token.isValid() ? token.getPayload()['role'] : 'guest';
        }),
      );
  }
}

在开发模式下工作正常,但是在生产模式下出现错误:

ERROR TypeError: Object(...) is not a function
    getRole http://localhost:4200/main.c8da7df94aad960dcfeb.js:1
    value http://localhost:4200/main.c8da7df94aad960dcfeb.js:1        

1 个答案:

答案 0 :(得分:0)

为我解决:

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

getRole(): Observable<string> {
  let result;
  this.authService.onTokenChange().subscribe((token: NbAuthJWTToken) => {
    if (token.isValid()) {
      result = token.getPayload()['roles'];
    } else {
      result = [];
    }
  });    
  return of(result);
}