Files
Mutual_Fund/frontend/lib/auth.ts
T

22 lines
936 B
TypeScript
Raw Normal View History

2026-09-14 20:31:06 +08:00
import { USER_TYPE } from "@/lib/roles";
const TOKEN_KEY = "huaxia_token";
/** 前端只负责展示友好名称,取值契约见 lib/roles.ts。 */
export const roleLabels: Record<string, string> = {
管理员: "管理员",
投顾: "投顾专员",
风控专员: "风控专员",
客户经理: "客户经理",
};
export function getToken() { if (typeof window === "undefined") return null; return localStorage.getItem(TOKEN_KEY); }
export function setToken(token: string) { localStorage.setItem(TOKEN_KEY, token); }
export function clearToken() { localStorage.removeItem(TOKEN_KEY); }
export function getRoleLabel(role?: string | null) { return role ? roleLabels[role] ?? "员工" : "员工"; }
/** 客户进入客户端,所有员工统一进入员工工作台。 */
export function getPostLoginPath(user?: { user_type?: string | null }) {
return user?.user_type === USER_TYPE.CUSTOMER ? "/account" : "/admin/common";
}