修复账户页 Pro 状态偶发性丢失
This commit is contained in:
@@ -1272,7 +1272,7 @@ export function AccountCenter() {
|
|||||||
|
|
||||||
const loadSnapshot = useCallback(async () => {
|
const loadSnapshot = useCallback(async () => {
|
||||||
setErrorText("");
|
setErrorText("");
|
||||||
try {
|
const attempt = async (retry: boolean): Promise<void> => {
|
||||||
const userPromise = supabaseReady
|
const userPromise = supabaseReady
|
||||||
? getSupabaseBrowserClient().auth.getUser()
|
? getSupabaseBrowserClient().auth.getUser()
|
||||||
: Promise.resolve({ data: { user: null as User | null } });
|
: Promise.resolve({ data: { user: null as User | null } });
|
||||||
@@ -1289,12 +1289,20 @@ export function AccountCenter() {
|
|||||||
]);
|
]);
|
||||||
setUser(userResult.data?.user ?? null);
|
setUser(userResult.data?.user ?? null);
|
||||||
if (!backendResult.ok) {
|
if (!backendResult.ok) {
|
||||||
|
if (retry && backendResult.status === 401) {
|
||||||
|
// Supabase session may not be hydrated yet; wait and retry once.
|
||||||
|
await new Promise((r) => setTimeout(r, 1200));
|
||||||
|
return attempt(false);
|
||||||
|
}
|
||||||
const raw = (await backendResult.text()).slice(0, 260);
|
const raw = (await backendResult.text()).slice(0, 260);
|
||||||
throw new Error(`HTTP ${backendResult.status} ${raw}`.trim());
|
throw new Error(`HTTP ${backendResult.status} ${raw}`.trim());
|
||||||
}
|
}
|
||||||
const backendJson = (await backendResult.json()) as AuthMeResponse;
|
const backendJson = (await backendResult.json()) as AuthMeResponse;
|
||||||
setBackend(backendJson);
|
setBackend(backendJson);
|
||||||
setUpdatedAt(new Date().toISOString());
|
setUpdatedAt(new Date().toISOString());
|
||||||
|
};
|
||||||
|
try {
|
||||||
|
await attempt(true);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
setErrorText(String(error));
|
setErrorText(String(error));
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user