diff --git a/src/api/demo.ts b/src/api/demo.ts index 85d9fc9..f60bf8c 100644 --- a/src/api/demo.ts +++ b/src/api/demo.ts @@ -43,9 +43,7 @@ export interface UserProfile { export interface AuthResult { demoToken: string - demoTokenExpiresAt?: number | null imToken: string - imTokenExpiresAt?: number | null profile: UserProfile } @@ -66,14 +64,6 @@ export const demoApi = { }) }, - refreshImToken(appId: string = APP_ID): Promise<{ imToken: string; imTokenExpiresAt?: number | null }> { - return request('/auth/refresh-im', { - method: 'POST', - skipAuth: false, - params: { appId }, - }) - }, - getProfile(): Promise { return request('/user/profile') }, diff --git a/src/context/AuthContext.tsx b/src/context/AuthContext.tsx index 4167be0..5771673 100644 --- a/src/context/AuthContext.tsx +++ b/src/context/AuthContext.tsx @@ -26,21 +26,10 @@ const AuthContext = createContext(null) export function AuthProvider({ children }: { children: React.ReactNode }) { const [state, setState] = useState({ ready: false, userId: null, profile: null }) - const initSDK = useCallback(async (profile: UserProfile, imToken: string, imTokenExpiresAt?: number | null) => { + const initSDK = useCallback(async (profile: UserProfile, imToken: string) => { const appKey = profile.appId || APP_ID await XuqmSDK.initialize({ appKey }) - await XuqmSDK.login({ - userId: profile.userId, - userSig: imToken, - expiresAt: imTokenExpiresAt ?? undefined, - profile, - refreshUserSig: async () => { - const refreshed = await demoApi.refreshImToken(appKey) - await save(K.IM_TOKEN, refreshed.imToken) - await save(K.IM_TOKEN_EXPIRES_AT, refreshed.imTokenExpiresAt ?? null) - return { userSig: refreshed.imToken, expiresAt: refreshed.imTokenExpiresAt ?? undefined } - }, - }) + await XuqmSDK.login({ userId: profile.userId, userSig: imToken }) setState({ ready: true, userId: profile.userId, profile }) UpdateSDK.checkAppUpdate() @@ -66,10 +55,9 @@ export function AuthProvider({ children }: { children: React.ReactNode }) { try { const demoToken = await load(K.DEMO_TOKEN) const imToken = await load(K.IM_TOKEN) - const imTokenExpiresAt = await load(K.IM_TOKEN_EXPIRES_AT) const profile = await load(K.PROFILE) if (demoToken && imToken && profile) { - await initSDK(profile, imToken, imTokenExpiresAt ?? undefined) + await initSDK(profile, imToken) return } } catch { @@ -80,12 +68,11 @@ export function AuthProvider({ children }: { children: React.ReactNode }) { restore() }, [initSDK]) - const handleAuthResult = useCallback(async (result: { demoToken: string; demoTokenExpiresAt?: number | null; imToken: string; imTokenExpiresAt?: number | null; profile: UserProfile }) => { + const handleAuthResult = useCallback(async (result: { demoToken: string; imToken: string; profile: UserProfile }) => { await save(K.DEMO_TOKEN, result.demoToken) await save(K.IM_TOKEN, result.imToken) - await save(K.IM_TOKEN_EXPIRES_AT, result.imTokenExpiresAt ?? null) await save(K.PROFILE, result.profile) - await initSDK(result.profile, result.imToken, result.imTokenExpiresAt ?? undefined) + await initSDK(result.profile, result.imToken) }, [initSDK]) const login = useCallback(async (userId: string, password: string) => { diff --git a/src/utils/storage.ts b/src/utils/storage.ts index 356fa63..827e775 100644 --- a/src/utils/storage.ts +++ b/src/utils/storage.ts @@ -3,7 +3,6 @@ import AsyncStorage from '@react-native-async-storage/async-storage' export const K = { DEMO_TOKEN: '@xuqm:demoToken', IM_TOKEN: '@xuqm:imToken', - IM_TOKEN_EXPIRES_AT: '@xuqm:imTokenExpiresAt', PROFILE: '@xuqm:profile', CONTACTS: '@xuqm:contacts', } as const @@ -23,5 +22,5 @@ export async function remove(key: string): Promise { } export async function clearSession(): Promise { - await Promise.all([K.DEMO_TOKEN, K.IM_TOKEN, K.IM_TOKEN_EXPIRES_AT, K.PROFILE].map(k => AsyncStorage.removeItem(k))) + await Promise.all([K.DEMO_TOKEN, K.IM_TOKEN, K.PROFILE].map(k => AsyncStorage.removeItem(k))) }