Skip to content

🧐[问题 | question] 如何在requestErrorConfig.ts 中requestInterceptors取出保存在currentUser中的token? #11398

@mendellin

Description

@mendellin

🧐 问题描述 | Problem description

💻 示例代码 | Sample code

在User\Login\index.tsx,用户登录成功后,保存数据到currentUser
//保存用户等信息
if (msg) {
flushSync(() => {
setInitialState((s) => ({
...s,
currentUser: msg.data,

        }));
      });
    }

currentUser 的定义
declare namespace API {
type CurrentUser = {
user_id?: number;
owner_id?:number;
username?:string;
fullname?: string;

**access_token?:string;**

is_admin?:number;
role_id?:number;


avatar?: string;
email?: string;
signature?: string;
title?: string;
group?: string;
tags?: { key?: string; label?: string }[];
notifyCount?: number;
unreadCount?: number;
country?: string;
access?: string;

geographic?: {
  province?: { label?: string; key?: string };
  city?: { label?: string; key?: string };
};
address?: string;
phone?: string;

};

在requestErrorConfig.ts中的requestInterceptors里面如何取出这个currentUser 里面的access_token并加到headers中去? 考虑到安全性,不使用localStorage

🚑 其他信息 | Other information

OS:

Node:

浏览器 | browser:

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions