如何解决生产模式下Nebular NbRoleProvider的问题
这是我的角色。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
解决方法
为我解决:
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);
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。