首页 > 解决方案 > 注销申请或清除本地存储值后,本地存储值仍返回之前的值

问题描述

当我以超级用户身份登录我的应用程序时,成功登录后,输入存储在本地存储中的“超级用户”。但是,当我以管理员用户身份登录时,“管理员”用户类型存储到本地存储中,它会调用管理员用户只能由超级用户访问的服务。

本地存储项设置为 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();
    } 
  }

标签: angular7

解决方案


推荐阅读