fix: 对接退出登录
This commit is contained in:
@@ -16,6 +16,8 @@ import { useTranslation } from 'react-i18next'
|
||||
import { PointsIcon, SearchIcon, SettingsIcon } from '@/components/icon'
|
||||
import EditProfileDrawer from '@/components/drawer/EditProfileDrawer'
|
||||
import Dropdown from '@/components/ui/dropdown'
|
||||
import Toast from '@/components/ui/Toast'
|
||||
import { signOut } from '@/lib/auth'
|
||||
|
||||
const { width: screenWidth } = Dimensions.get('window')
|
||||
const GALLERY_GAP = 2
|
||||
@@ -53,13 +55,44 @@ export default function My() {
|
||||
const [profileName, setProfileName] = useState('乔乔乔乔')
|
||||
|
||||
// 处理设置菜单选择
|
||||
const handleSettingsSelect = (value: string) => {
|
||||
const handleSettingsSelect = async (value: string) => {
|
||||
if (value === 'changePassword') {
|
||||
router.push('/changePassword' as any)
|
||||
} else if (value === 'language') {
|
||||
// 切换语言
|
||||
const newLang = i18n.language === 'zh-CN' ? 'en-US' : 'zh-CN'
|
||||
i18n.changeLanguage(newLang)
|
||||
} else if (value === 'logout') {
|
||||
// 退出登录
|
||||
console.log('🚪 点击退出登录')
|
||||
const confirmText = i18n.language === 'zh-CN' ? '确定' : 'OK'
|
||||
const cancelText = i18n.language === 'zh-CN' ? '取消' : 'Cancel'
|
||||
const message = i18n.language === 'zh-CN' ? '确定要退出登录吗?' : 'Are you sure you want to logout?'
|
||||
|
||||
Toast.showActionSheet({
|
||||
itemList: [message, confirmText, cancelText]
|
||||
}).then(async (index) => {
|
||||
// index 1 是确定按钮
|
||||
if (index === 1) {
|
||||
console.log('🚪 开始执行退出登录')
|
||||
try {
|
||||
Toast.showLoading({ title: i18n.language === 'zh-CN' ? '退出中...' : 'Logging out...' })
|
||||
// 调用 better-auth 的 signOut 方法
|
||||
await signOut()
|
||||
Toast.hideLoading()
|
||||
console.log('✅ 退出登录成功,跳转到登录页')
|
||||
Toast.show(i18n.language === 'zh-CN' ? '退出登录成功' : 'Logged out successfully')
|
||||
// 跳转到登录页面(注意:路由是 /auth 不是 /login)
|
||||
router.replace('/auth')
|
||||
} catch (error) {
|
||||
Toast.hideLoading()
|
||||
console.error('❌ 退出登录失败:', error)
|
||||
Toast.show(i18n.language === 'zh-CN' ? '退出登录失败,请稍后重试' : 'Failed to logout, please try again later')
|
||||
}
|
||||
}
|
||||
}).catch(() => {
|
||||
console.log('❌ 取消退出登录')
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -75,6 +108,7 @@ export default function My() {
|
||||
const settingsOptions = [
|
||||
{ label: t('my.changePassword'), value: 'changePassword' },
|
||||
{ label: getLanguageLabel(), value: 'language' },
|
||||
{ label: t('my.logout'), value: 'logout' },
|
||||
]
|
||||
|
||||
return (
|
||||
|
||||
Reference in New Issue
Block a user