feat:账号设置+密码重置

This commit is contained in:
xiaozhu
2026-09-02 10:10:41 +08:00
committed by tao.chen
parent 856bdbae8d
commit 5f5eb739c2
13 changed files with 815 additions and 29 deletions
+45 -1
View File
@@ -48,6 +48,14 @@ type AuthContextValue = {
loading: boolean;
login: (username: string, password: string) => Promise<void>;
logout: () => Promise<void>;
updateProfile: (input: {
display_name?: string;
email?: string;
}) => Promise<void>;
changePassword: (input: {
current_password: string;
new_password: string;
}) => Promise<void>;
setCurrentWorkspace: (workspaceId: string) => void;
refreshWorkspaces: () => Promise<void>;
};
@@ -162,6 +170,27 @@ export function AuthProvider({ children }: { children: ReactNode }) {
}
}, [navigate]);
const updateProfile = useCallback(async (input: {
display_name?: string;
email?: string;
}) => {
const result = await authRequest<{ user: AuthUser }>("/api/v1/auth/me", {
method: "PATCH",
body: JSON.stringify(input),
});
setUser(result.user);
}, []);
const changePassword = useCallback(async (input: {
current_password: string;
new_password: string;
}) => {
await authRequest<{ password_changed: boolean }>("/api/v1/auth/password", {
method: "POST",
body: JSON.stringify(input),
});
}, []);
const setCurrentWorkspace = useCallback((workspaceId: string) => {
const workspace = workspaces.find((item) => item.workspace_id === workspaceId);
if (!workspace) return;
@@ -193,9 +222,22 @@ export function AuthProvider({ children }: { children: ReactNode }) {
loading,
login,
logout,
updateProfile,
changePassword,
setCurrentWorkspace,
refreshWorkspaces,
}), [currentWorkspace, loading, login, logout, setCurrentWorkspace, user, workspaces, refreshWorkspaces]);
}), [
changePassword,
currentWorkspace,
loading,
login,
logout,
refreshWorkspaces,
setCurrentWorkspace,
updateProfile,
user,
workspaces,
]);
if (loading) {
return (
@@ -283,6 +325,8 @@ export function useApi(): WorkspaceBoundApi {
rawApi.updatePlatformEmployee(userId, input),
deleteEmployee: (userId) => rawApi.deleteEmployee(workspaceId, userId),
deletePlatformEmployee: (userId) => rawApi.deletePlatformEmployee(userId),
resetPlatformEmployeePassword: (userId, newPassword) =>
rawApi.resetPlatformEmployeePassword(userId, newPassword),
// Role Management - 角色管理接口(跨 workspace,不需要传入 workspaceId
listPlatformRoles: () => rawApi.listPlatformRoles(),
getPlatformRole: (roleCode) => rawApi.getPlatformRole(roleCode),