У меня есть угловое приложение, которое использует auth0 для аутентификации. Проблема, с которой я сталкиваюсь, заключается в том, что при успешном входе в систему кажется, что обратный вызов блокировки не вызывается. Только после обновления вручную страницы будут переданы данные профиля в локальное хранилище.auth0 callback не задает дату профиля после входа в систему angular2
Когда пользователь входит в систему, мне нужно захватить этот объект профиля и использовать его в классе компонентов. Этот код работает только после того, как я обновил страницу вручную после успешного входа в систему. Вот мой код (включая только важные части).
auth.service
lock = new Auth0Lock('.....9cNzyzJ3DZc2VpDyXSYF5', '.....12.auth0.com', {});
user: any;
constructor() {
// Add callback for lock `authenticated` event
this.user = JSON.parse(localStorage.getItem('profile'));
this.lock.on("authenticated", (authResult:any) => {
this.lock.getProfile(authResult.idToken, function(error: any, profile: any){
if(error){
throw new Error(error);
}
localStorage.setItem('id_token', authResult.idToken);
localStorage.setItem('profile', JSON.stringify(profile));
this.user = profile;
});
});
}
public login() {
// Call the show method to display the widget.
this.lock.show();
console.log('login func');
};
nav.component
constructor(private auth: Auth, private groupsService: GroupsService){
}
ngOnInit(){
// need to access the profile object here. Ocject is correctly logged only after refreshing.
console.log(JSON.parse(localStorage.getItem('profile')));
this.groupsService.getGroups(this.userId).subscribe(groups => {
this.groups = groups;
// sort the groups
this.groups.sort((a, b) => new Date(b.date_created).getTime() - new Date(a.date_created).getTime());
});
}
Эй, у меня такая же проблема. Как вы это решили? – wuno