登录后,auth0将我重定向回angular2上的回调url。我如何使它走到我给路由的路径,而不重定向回呼url。
发布于 2017-01-04 14:05:23
我一直在努力解决同样的问题。看来你有几个选择。
( a)使用弹出模式
这很容易实现,但是Auth0建议而不是使用它,因为浏览器不一致。(即一些iOS上的IE和Chrome/Firefox)
它就像在锁选项对象中添加一个标志一样简单
var lockOptions = {
auth: {
redirect: false
}
}b)在LocalStorage中保存状态
Auth0建议将状态保存到LocalStorage,如果您想让用户恢复到他们停止的地方。
因此,在触发lock.show()之前,您可以将当前的URL/path/state/etc保存到本地存储中。在我的例子中,我使用的是authGuard。
canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): Promise<boolean> {
if (this.authService.isLoggedIn) {
return Promise.resolve(true);
}
// Store the attempted URL for redirecting after auth
localStorage.setItem('redirectUrl', state.url);
// Navigate to the login page
this.router.navigate([`${environment.loggedOutRoute}`]);
return Promise.resolve(false);
}然后在你自己的电话里:
// On authentication
this.lock.on('authenticated', (authResult: any) => {
// Save the token in LS
localStorage.setItem('token', authResult.idToken);
// Hide the login modal
this.lock.hide();
// Redirect the user
const redirectUrl: string = localStorage.getItem('redirectUrl');
if (redirectUrl) {
this.router.navigate([redirectUrl]);
} else {
this.router.navigate(['/overview']);
}
});https://stackoverflow.com/questions/39199897
复制相似问题