diff --git a/app/profile.tsx b/app/profile.tsx index edd389e..69d7332 100644 --- a/app/profile.tsx +++ b/app/profile.tsx @@ -153,12 +153,25 @@ export default observer(function ProfilePage() { Toast.show({ title: err.message || '修改失败,请重试' }) return } - Toast.hideModal() Toast.show({ title: '密码已修改,请重新登录' }) - // 退出登录 - await userStore.signOut() // 跳转到登录页 - router.replace('/auth') + Toast.hideModal() + // 2. 等待 Modal 关闭动画完成(关键:避免 View 空指针) + setTimeout(() => { + // 3. 清空导航栈 + router.dismissAll() + + // 4. 执行登出 + userStore.signOut() + + // 5. 跳转到登录页 + router.replace('/auth') + + // 6. 显示提示 + setTimeout(() => { + Toast.show({ title: '已退出登录' }) + }, 100) + }, 400) } catch (e) { Toast.show({ title: '修改失败,请重试' }) } diff --git a/app/settings.tsx b/app/settings.tsx index 75a0d07..44e89f5 100644 --- a/app/settings.tsx +++ b/app/settings.tsx @@ -24,11 +24,25 @@ export default observer(function SettingsPage() { content="确定要退出登录吗?" onCancel={Toast.hideModal} onConfirm={async () => { - await signOut() - Toast.show({ title: '已退出登录' }) - router.replace('/auth') - // 关闭modal + // 1. 立即关闭 Modal,避免在动画期间操作路由 Toast.hideModal() + + // 2. 等待 Modal 关闭动画完成(关键:避免 View 空指针) + setTimeout(() => { + // 3. 清空导航栈 + router.dismissAll() + + // 4. 执行登出 + signOut() + + // 5. 跳转到登录页 + router.replace('/auth') + + // 6. 显示提示 + setTimeout(() => { + Toast.show({ title: '已退出登录' }) + }, 100) + }, 400) }} />, ) diff --git a/lib/fetch-logger.ts b/lib/fetch-logger.ts index 9653812..2c07544 100644 --- a/lib/fetch-logger.ts +++ b/lib/fetch-logger.ts @@ -1,6 +1,5 @@ -import { router } from 'expo-router' - -import { storage } from './storage' +import { storage as storage2 } from '../utils/storage' +import { storage } from './storage.native' interface FetchLoggerOptions { enableLogging?: boolean @@ -42,9 +41,9 @@ export const createFetchWithLogger = (options: FetchLoggerOptions = {}) => { const response = await originalFetch(input, init) if (response.status === 401) { - console.warn('🔐 401 未授权,跳转到登录页') + console.warn('🔐 401 未授权,清空登录状态') // router.replace('/auth') - router.replace('/auth') + storage2.set('isLogin', false) } return response