登录验证需要在实际登录之前进行
Posted
技术标签:
【中文标题】登录验证需要在实际登录之前进行【英文标题】:Login validation needs to go before actual login 【发布时间】:2017-04-14 14:12:02 【问题描述】:我做了一个特殊的类验证来检查用户是否登录,如果不是,它不应该打开它想要继续的页面。问题是当我添加行时,我的程序不再将我路由到需要去的组件。
Validation.ts
export class validation
user = ;
loggedinvalidation(user)
if (user)
this.user = user;
console.log("test login");
return true
else
this.user = ;
console.log("test logout");
return false
app.component.ts
export class AppComponent
...
login(email:any, password:any)
this.af.auth.login( email: email, password: password ,
provider: AuthProviders.Password,
method: AuthMethods.Password
);
this.modal.close();
this.router.navigate(['dashboard']);
dashboard.component.ts
export class DashboardComponent
constructor(public af: AngularFire, public router: Router)
this.vali = new validation();
this.af.auth.subscribe(user =>
if (this.vali.loggedinvalidation(user))
this.af.auth.subscribe(auth =>
...
);
else
this.router.navigate(['/']);
);
当我运行程序并从 /'' 开始时,它工作正常,但是当我尝试登录时,它在我的控制台中给了我这个。问题是它首先给了我一个测试注销,这就是它没有路由到仪表板的原因。知道如何更快地或在实际发生登录后获得验证吗?
test logout
test login
【问题讨论】:
【参考方案1】:解析器可能会对您有所帮助。您仍然在使用逻辑上正确的身份验证过程,但更精确的解决方案可以无缝地进行身份验证:)
https://www.codementor.io/max_diachenko/tutorials/angular-2-route-resolves--typescript-du1089pdm
【讨论】:
好吧,我查看了链接,但我仍然不知道如何解决我的路由问题以上是关于登录验证需要在实际登录之前进行的主要内容,如果未能解决你的问题,请参考以下文章
登录sql时 window身份验证登录和sqlserver验证登录有啥区别?