각도 응용 프로그램의 권한 서비스에 역할을 저장하는 데 사용되는 배열에 문제가 있습니다. 나는 로그인에 auth0 서비스를 사용하고 auth.service.ts은 다음과 같습니다. 로그인 handleAuthentication 기능이 호출되고 새로 고침 단추를 클릭 할 때까지 모든 것이 잘 작동됩니다Typescript, Angular4 : 브라우저를 새로 고친 후 배열이 비어 짐
@Injectable()
export class AuthService {
userProfile: any;
private roles: string[] = [];
...
public handleAuthentication(): void {
this.auth0.parseHash((err, authResult) => {
if (authResult && authResult.accessToken && authResult.idToken) {
window.location.hash = '';
this.setSession(authResult);
this.getRoles(authResult);
this.router.navigate(['/']);
} else if (err) {
this.router.navigate(['/']);
console.log(err);
alert(`Error: ${err.error}. Check the console for further details.`);
}
});}
//THIS IS getRole function
private getRoles(authResult){
let jwtHelper = new JwtHelper();
let decodedToken = jwtHelper.decodeToken(authResult.idToken);
this.roles = decodedToken['https://tobenorme.com/roles'];
}
후. 그런 다음 역할 배열이 빈 배열을 반환하고 더 이상 역할을 얻을 수 없습니다. 로컬 저장소에 저장하려고했으나 브라우저에서 편집 할 수 있습니다.