검증게시판 단계 추가
This commit is contained in:
@@ -6,16 +6,20 @@ import React, {
|
||||
useMemo,
|
||||
useState,
|
||||
} from 'react';
|
||||
import { Capacitor } from '@capacitor/core';
|
||||
import {
|
||||
clearAuthSession,
|
||||
fetchAuthMe,
|
||||
getAuthSession,
|
||||
initStorage,
|
||||
refreshApiBaseFromStorage,
|
||||
setAuthSession,
|
||||
storageGetSync,
|
||||
storageRemove,
|
||||
type AuthSession,
|
||||
type LoginResponse,
|
||||
} from '../lib/shared';
|
||||
import { invalidateAppSettingsCache } from '../hooks/useAppSettings';
|
||||
import { invalidateAppSettingsCache, reloadAppSettingsCache } from '../hooks/useAppSettings';
|
||||
|
||||
function normalizeRole(role: string): AuthSession['role'] {
|
||||
return role === 'ADMIN' ? 'ADMIN' : 'USER';
|
||||
@@ -53,10 +57,22 @@ export function AuthProvider({ children }: { children: React.ReactNode }) {
|
||||
let cancelled = false;
|
||||
void (async () => {
|
||||
await initStorage();
|
||||
if (Capacitor.isNativePlatform()) {
|
||||
const savedApi = storageGetSync('gc_api_base_url');
|
||||
if (savedApi && /localhost|127\.0\.0\.1/i.test(savedApi)) {
|
||||
await storageRemove('gc_api_base_url');
|
||||
}
|
||||
}
|
||||
refreshApiBaseFromStorage();
|
||||
const stored = getAuthSession();
|
||||
if (stored) {
|
||||
try {
|
||||
const me = await fetchAuthMe();
|
||||
const me = await Promise.race([
|
||||
fetchAuthMe(),
|
||||
new Promise<null>((_, reject) => {
|
||||
setTimeout(() => reject(new Error('session verify timeout')), 15_000);
|
||||
}),
|
||||
]);
|
||||
if (me && !cancelled) {
|
||||
const session = loginToSession(me);
|
||||
setAuthSession(session);
|
||||
@@ -84,7 +100,9 @@ export function AuthProvider({ children }: { children: React.ReactNode }) {
|
||||
setAuthUser(session);
|
||||
setGuestMode(false);
|
||||
invalidateAppSettingsCache();
|
||||
setSessionKey(k => k + 1);
|
||||
void reloadAppSettingsCache().finally(() => {
|
||||
setSessionKey(k => k + 1);
|
||||
});
|
||||
}, []);
|
||||
|
||||
const handleGuestEnter = useCallback(() => {
|
||||
@@ -92,7 +110,9 @@ export function AuthProvider({ children }: { children: React.ReactNode }) {
|
||||
setAuthUser(null);
|
||||
setGuestMode(true);
|
||||
invalidateAppSettingsCache();
|
||||
setSessionKey(k => k + 1);
|
||||
void reloadAppSettingsCache().finally(() => {
|
||||
setSessionKey(k => k + 1);
|
||||
});
|
||||
}, []);
|
||||
|
||||
const handleLogout = useCallback(async () => {
|
||||
|
||||
Reference in New Issue
Block a user