feat(web): 开发账户修改、密码修改功能

This commit is contained in:
R524809
2026-09-03 16:56:53 +08:00
parent 46d98ab11e
commit 06a3a4da75
9 changed files with 435 additions and 25 deletions
+15 -1
View File
@@ -1,4 +1,9 @@
import type { AuthSessionResponse, LoginRequest, RegisterRequest } from '@atlas/contracts';
import type {
AuthSessionResponse,
AuthUser,
LoginRequest,
RegisterRequest,
} from '@atlas/contracts';
import { api } from '@/services/api';
import type { MeResult, RefreshResult } from '@/types/auth';
@@ -14,4 +19,13 @@ export const authApi = {
logout: () => api.post<void>('/auth/logout'),
me: () => api.get<MeResult>('/auth/me'),
/**
* 【临时 mock】修改资料:PATCH 类接口契约尚未提供(缺口已提报后端 AI)。
* 仅在本地模拟成功返回,数据不持久化,刷新即恢复;契约交付后替换为真实调用并删除本实现。
*/
updateProfile: (payload: { display_name: string }): Promise<{ user: Partial<AuthUser> }> =>
new Promise((resolve) => {
setTimeout(() => resolve({ user: { display_name: payload.display_name } }), 300);
}),
};
+8 -2
View File
@@ -26,6 +26,8 @@ interface SessionContextValue {
session: SessionState | null;
/** 登录 / 注册成功后写入会话 */
applyAuthSession: (payload: AuthSessionResponse) => void;
/** 修改资料成功后更新本地会话中的用户信息 */
applyProfileUpdate: (user: SessionState['user']) => void;
/** 撤销服务端会话并清除本地状态;网络失败也保证本地登出 */
logout: () => Promise<void>;
}
@@ -74,6 +76,10 @@ export function SessionProvider({ children }: { children: ReactNode }) {
setStatus('authenticated');
}, []);
const applyProfileUpdate = useCallback((user: SessionState['user']) => {
setSession((prev) => (prev ? { ...prev, user } : prev));
}, []);
const logout = useCallback(async () => {
try {
await authApi.logout();
@@ -95,8 +101,8 @@ export function SessionProvider({ children }: { children: ReactNode }) {
}, []);
const value = useMemo(
() => ({ status, session, applyAuthSession, logout }),
[status, session, applyAuthSession, logout]
() => ({ status, session, applyAuthSession, applyProfileUpdate, logout }),
[status, session, applyAuthSession, applyProfileUpdate, logout]
);
return <SessionContext.Provider value={value}>{children}</SessionContext.Provider>;