我一直作为实习生在一个项目上工作,是新的意思这是我面临的问题,我被要求创建一个完成的登录页面,但要注意的是该登录是由公司方认证的。因此,基本上在我的登录组件中,以下逻辑是我已经实现的。login.component.ts文件的组件类似于以下
onSubmit(event) {
event.preventDefault()
console.log('value',this.loginForm.value)
if(this.errorMail.length === 0) {
this.loginService.login(this.loginForm.value).subscribe((res:any) => {
console.log('login response', res)
if(res.auth.success === true) {
localStorage.setItem('auth', JSON.stringify(res.auth))
this.loginService.loggedIn$.next(res.auth)
this.router.navigateByUrl('/search/list')
} else {
this.errorMail='Email or password is not valid'
}
})
}
以下是login.service.ts
login(creds) {
// console.log('creds',creds)
return this.http.post<LoginResponse>('url-of-company', {creds})
}
以及在我具有注销按钮的标题组件中:header.component.ts的内容;
onLogout(){
this.authService.logout();
this.router.navigateByUrl('/');
}
上面代码中的authService是从header.service.ts导入的,而header.service.ts就像这样;
logout() {
this.http.delete<LoginResponse>('url-of-comapy');
this.router.navigate(['/']);
}
基本上,我正在尝试删除我从公司网址获取的身份验证凭据,并将其重定向到登录页面
请在出现问题的地方帮助我,在我的情况下我应该在哪里进行纠正以及注销该怎么做。
[我认为您需要做的是从localStorage
中删除凭据,而不是从数据库中删除凭据,这是您在logout()
函数中的上面代码中试图做的事情。