注销应用程序或清除本地存储值后,本地存储值仍返回先前的值

时间:2019-07-29 06:35:53

标签: angular7

当我以超级用户用户身份登录我的应用程序时,成功登录后,键入存储在本地存储中的“超级用户”。但是,当我以管理员用户身份登录时,存储在localstorage中的'admin'用户类型被登录,它将调用只有超级用户才能访问的服务。

将本地存储项设置为userInfo键的登录组件

this.commonService.login(loginData).subscribe(res => {   
  let encodeCode = AES.encrypt(res['user'].organizationId, myGlobals.ENC_KEY).toString();
      // if (res['user'].type == 'admin'){
      //   this.router.navigate(["../admin/organization/edit"], { queryParams: { id: encodeCode }, relativeTo: this.route });
      // } else {
        this.router.navigate([""]);
      // }  
      this.spinner.hide(); 
      Toast.fire({
        type: 'success',
        title: 'Logged in successfully'
      })    
      this.isError = false;
      localStorage.setItem('token', res['accessToken']);
      localStorage.setItem("userInfo", JSON.stringify(res['user'])); 
      let defaultSet: any = { org: true, user: true, flow: true, conn: true };    
      localStorage.setItem("default", JSON.stringify(defaultSet));
    }, error => {
      this.isError = true;
    });

已设置条件的组织组件

ngOnInit() {
    this.searchValid();
    if (this.userType.type == 'superuser') {
      this.organizationList();
    } else {
      this.projectList();
    }
    $("#orgLink").addClass('active');
    // Initialize Socket
    if (myGlobals.SOCKET) {
      this.initSocket();
    } 
  }

0 个答案:

没有答案