MCPcopy
hub / github.com/graphif/project-graph / initAuth

Function initAuth

app/src/main.tsx:84–107  ·  view source on GitHub ↗

初始化认证状态:从持久化存储中恢复 session

()

Source from the content-addressed store, hash-verified

82
83/** 初始化认证状态:从持久化存储中恢复 session */
84async function initAuth() {
85 if (!authClient) {
86 store.set(isAuthLoadingAtom, false);
87 return;
88 }
89 try {
90 const session = await UserState.getSession();
91 if (session?.token) {
92 // 验证 session 是否仍然有效
93 const { data } = await authClient.getSession();
94 if (data?.user) {
95 store.set(currentUserAtom, data.user as AuthUser);
96 } else {
97 // token 失效,清理本地存储
98 await UserState.clearSession();
99 }
100 }
101 } catch {
102 // 网络错误等不影响启动,清理本地 session 即可
103 await UserState.clearSession();
104 } finally {
105 store.set(isAuthLoadingAtom, false);
106 }
107}
108
109/** 加载语言文件 */
110async function loadLanguageFiles() {

Callers 1

main.tsxFile · 0.85

Calls 1

setMethod · 0.45

Tested by

no test coverage detected