fix: 对接退出登录
This commit is contained in:
parent
37a4a2f807
commit
fb719c6ea2
|
|
@ -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 (
|
||||
|
|
|
|||
|
|
@ -1,40 +1,21 @@
|
|||
import { loomart } from "@/lib/auth"
|
||||
import { OWNER_ID } from "@/lib/auth"
|
||||
import { ApiError } from "@/lib/types"
|
||||
import { root } from '@repo/core'
|
||||
import { ActivityController, ListActivitiesResult } from "@repo/sdk"
|
||||
import { useState } from "react"
|
||||
export const useActivates = () => {
|
||||
const [loading, setLoading] = useState<boolean>(false)
|
||||
const [error, setError] = useState<ApiError | null>(null)
|
||||
const [data, setData] = useState<{
|
||||
activities: {
|
||||
title: string;
|
||||
titleEn: string;
|
||||
desc: string;
|
||||
descEn: string;
|
||||
coverUrl: string;
|
||||
link: string;
|
||||
createdAt: Date;
|
||||
updatedAt: Date;
|
||||
id: string;
|
||||
videoUrl?: string | null | undefined;
|
||||
isActive?: boolean | null | undefined;
|
||||
sortOrder?: number | null | undefined;
|
||||
}[];
|
||||
total: number;
|
||||
page: number;
|
||||
limit: number;
|
||||
totalPages: number;
|
||||
}>()
|
||||
const [data, setData] = useState<ListActivitiesResult>()
|
||||
const load = async () => {
|
||||
try {
|
||||
setLoading(true)
|
||||
const { data, error } = await loomart.activities.list({ isActive: true })
|
||||
console.log({ data, error })
|
||||
if (error) {
|
||||
setError(error)
|
||||
return;
|
||||
}
|
||||
const c = root.get(ActivityController)
|
||||
const data = await c.list({ page: 1, limit: 10, isActive: true, orderBy: 'sortOrder', order: 'desc', ownerId: OWNER_ID })
|
||||
setData(data)
|
||||
} catch (e) {
|
||||
setError(e as ApiError)
|
||||
} finally {
|
||||
setLoading(false)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
19
lib/auth.ts
19
lib/auth.ts
|
|
@ -3,16 +3,15 @@ import 'reflect-metadata'
|
|||
import { expoClient } from '@better-auth/expo/client'
|
||||
import { createSkerClientPlugin } from '@repo/sdk'
|
||||
import {
|
||||
adminClient,
|
||||
emailOTPClient,
|
||||
genericOAuthClient,
|
||||
jwtClient,
|
||||
organizationClient,
|
||||
phoneNumberClient,
|
||||
usernameClient,
|
||||
adminClient,
|
||||
emailOTPClient,
|
||||
genericOAuthClient,
|
||||
jwtClient,
|
||||
organizationClient,
|
||||
phoneNumberClient,
|
||||
usernameClient,
|
||||
} from 'better-auth/client/plugins'
|
||||
import { createAuthClient } from 'better-auth/react'
|
||||
import Constants from 'expo-constants'
|
||||
|
||||
import { fetchWithLogger, TOKEN_KEY } from './fetch-logger'
|
||||
import type { Subscription } from './plugins/stripe'
|
||||
|
|
@ -21,7 +20,7 @@ import { storage } from './storage'
|
|||
import type { ApiError } from './types'
|
||||
|
||||
// 商户ID配置 - 从环境变量或应用配置中读取
|
||||
const MERCHANT_ID = Constants.expoConfig?.extra?.merchantId || ''
|
||||
export const OWNER_ID = 't0m9cketSQdCA6cHXI9mXQLJPM9LDIw5'
|
||||
|
||||
export interface CreditBalance {
|
||||
tokenUsage: number
|
||||
|
|
@ -92,7 +91,7 @@ export const authClient = createAuthClient({
|
|||
'Content-Type': 'application/json',
|
||||
// x-ownerid: 商户ID(如果后端需要)
|
||||
// 如果 MERCHANT_ID 为空,则不添加此 header
|
||||
...(MERCHANT_ID && { 'x-ownerid': MERCHANT_ID }),
|
||||
...(OWNER_ID && { 'x-ownerid': OWNER_ID }),
|
||||
},
|
||||
auth: {
|
||||
type: 'Bearer',
|
||||
|
|
|
|||
|
|
@ -7,7 +7,8 @@
|
|||
"changePassword": "Change Password",
|
||||
"language": "Language",
|
||||
"languageSwitch": "Language: 中文",
|
||||
"languageSwitchEn": "Language: English"
|
||||
"languageSwitchEn": "Language: English",
|
||||
"logout": "Logout"
|
||||
},
|
||||
"changePassword": {
|
||||
"title": "Change Password",
|
||||
|
|
|
|||
|
|
@ -7,7 +7,8 @@
|
|||
"changePassword": "修改密码",
|
||||
"language": "语言",
|
||||
"languageSwitch": "语言: 中文",
|
||||
"languageSwitchEn": "Language: English"
|
||||
"languageSwitchEn": "Language: English",
|
||||
"logout": "退出登录"
|
||||
},
|
||||
"changePassword": {
|
||||
"title": "修改密码",
|
||||
|
|
|
|||
Loading…
Reference in New Issue