refactor(auth): 管理端清除多身份残留(identities/currentIdentity/selectIdentity/Identity)
- auth.tsx/type 去 identities/currentIdentity 状态与 Identity 类型,role 恒取 user.role - api/auth.ts 删 selectIdentity、getSavedUser/saveUser 去 identity 字段 - types.ts LoginResponse 去 identities/identity_id/port/identity_name 字段 Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
+3
-11
@@ -1,5 +1,5 @@
|
||||
import { api, setToken } from "@/api/client";
|
||||
import type { Identity, LoginResponse } from "@/types";
|
||||
import type { LoginResponse } from "@/types";
|
||||
|
||||
export async function login(username: string, password: string): Promise<LoginResponse> {
|
||||
const res = await api.post<LoginResponse>("/auth/login", { username, password });
|
||||
@@ -7,14 +7,6 @@ export async function login(username: string, password: string): Promise<LoginRe
|
||||
return res;
|
||||
}
|
||||
|
||||
export async function selectIdentity(identityId: string): Promise<LoginResponse> {
|
||||
const res = await api.post<LoginResponse>("/auth/select-identity", {
|
||||
identity_id: identityId,
|
||||
});
|
||||
setToken(res.token);
|
||||
return res;
|
||||
}
|
||||
|
||||
// ---- 四种登录:短信验证码 / 微信扫码 / 小程序扫码 ----
|
||||
|
||||
export async function sendCode(phone: string): Promise<{ sent: boolean; message: string; stub_code?: string }> {
|
||||
@@ -64,7 +56,7 @@ export async function fetchMe(): Promise<Record<string, unknown>> {
|
||||
return api.get("/auth/me");
|
||||
}
|
||||
|
||||
export function getSavedUser(): { username?: string; role?: string; identity?: Identity } | null {
|
||||
export function getSavedUser(): { username?: string; role?: string } | null {
|
||||
try {
|
||||
return JSON.parse(localStorage.getItem("@cloud-opc-admin/user") || "null");
|
||||
} catch {
|
||||
@@ -72,7 +64,7 @@ export function getSavedUser(): { username?: string; role?: string; identity?: I
|
||||
}
|
||||
}
|
||||
|
||||
export function saveUser(user: { username?: string; role?: string; identity?: Identity } | null) {
|
||||
export function saveUser(user: { username?: string; role?: string } | null) {
|
||||
if (user) localStorage.setItem("@cloud-opc-admin/user", JSON.stringify(user));
|
||||
else localStorage.removeItem("@cloud-opc-admin/user");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user