fix: 对接退出登录

This commit is contained in:
imeepos 2026-01-13 17:03:14 +08:00
parent 37a4a2f807
commit fb719c6ea2
5 changed files with 56 additions and 40 deletions

View File

@ -16,6 +16,8 @@ import { useTranslation } from 'react-i18next'
import { PointsIcon, SearchIcon, SettingsIcon } from '@/components/icon' import { PointsIcon, SearchIcon, SettingsIcon } from '@/components/icon'
import EditProfileDrawer from '@/components/drawer/EditProfileDrawer' import EditProfileDrawer from '@/components/drawer/EditProfileDrawer'
import Dropdown from '@/components/ui/dropdown' import Dropdown from '@/components/ui/dropdown'
import Toast from '@/components/ui/Toast'
import { signOut } from '@/lib/auth'
const { width: screenWidth } = Dimensions.get('window') const { width: screenWidth } = Dimensions.get('window')
const GALLERY_GAP = 2 const GALLERY_GAP = 2
@ -53,13 +55,44 @@ export default function My() {
const [profileName, setProfileName] = useState('乔乔乔乔') const [profileName, setProfileName] = useState('乔乔乔乔')
// 处理设置菜单选择 // 处理设置菜单选择
const handleSettingsSelect = (value: string) => { const handleSettingsSelect = async (value: string) => {
if (value === 'changePassword') { if (value === 'changePassword') {
router.push('/changePassword' as any) router.push('/changePassword' as any)
} else if (value === 'language') { } else if (value === 'language') {
// 切换语言 // 切换语言
const newLang = i18n.language === 'zh-CN' ? 'en-US' : 'zh-CN' const newLang = i18n.language === 'zh-CN' ? 'en-US' : 'zh-CN'
i18n.changeLanguage(newLang) 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 = [ const settingsOptions = [
{ label: t('my.changePassword'), value: 'changePassword' }, { label: t('my.changePassword'), value: 'changePassword' },
{ label: getLanguageLabel(), value: 'language' }, { label: getLanguageLabel(), value: 'language' },
{ label: t('my.logout'), value: 'logout' },
] ]
return ( return (

View File

@ -1,40 +1,21 @@
import { loomart } from "@/lib/auth" import { OWNER_ID } from "@/lib/auth"
import { ApiError } from "@/lib/types" import { ApiError } from "@/lib/types"
import { root } from '@repo/core'
import { ActivityController, ListActivitiesResult } from "@repo/sdk"
import { useState } from "react" import { useState } from "react"
export const useActivates = () => { export const useActivates = () => {
const [loading, setLoading] = useState<boolean>(false) const [loading, setLoading] = useState<boolean>(false)
const [error, setError] = useState<ApiError | null>(null) const [error, setError] = useState<ApiError | null>(null)
const [data, setData] = useState<{ const [data, setData] = useState<ListActivitiesResult>()
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 load = async () => { const load = async () => {
try { try {
setLoading(true) setLoading(true)
const { data, error } = await loomart.activities.list({ isActive: true }) const c = root.get(ActivityController)
console.log({ data, error }) const data = await c.list({ page: 1, limit: 10, isActive: true, orderBy: 'sortOrder', order: 'desc', ownerId: OWNER_ID })
if (error) {
setError(error)
return;
}
setData(data) setData(data)
} catch (e) { } catch (e) {
setError(e as ApiError)
} finally {
setLoading(false) setLoading(false)
} }
} }

View File

@ -3,16 +3,15 @@ import 'reflect-metadata'
import { expoClient } from '@better-auth/expo/client' import { expoClient } from '@better-auth/expo/client'
import { createSkerClientPlugin } from '@repo/sdk' import { createSkerClientPlugin } from '@repo/sdk'
import { import {
adminClient, adminClient,
emailOTPClient, emailOTPClient,
genericOAuthClient, genericOAuthClient,
jwtClient, jwtClient,
organizationClient, organizationClient,
phoneNumberClient, phoneNumberClient,
usernameClient, usernameClient,
} from 'better-auth/client/plugins' } from 'better-auth/client/plugins'
import { createAuthClient } from 'better-auth/react' import { createAuthClient } from 'better-auth/react'
import Constants from 'expo-constants'
import { fetchWithLogger, TOKEN_KEY } from './fetch-logger' import { fetchWithLogger, TOKEN_KEY } from './fetch-logger'
import type { Subscription } from './plugins/stripe' import type { Subscription } from './plugins/stripe'
@ -21,7 +20,7 @@ import { storage } from './storage'
import type { ApiError } from './types' import type { ApiError } from './types'
// 商户ID配置 - 从环境变量或应用配置中读取 // 商户ID配置 - 从环境变量或应用配置中读取
const MERCHANT_ID = Constants.expoConfig?.extra?.merchantId || '' export const OWNER_ID = 't0m9cketSQdCA6cHXI9mXQLJPM9LDIw5'
export interface CreditBalance { export interface CreditBalance {
tokenUsage: number tokenUsage: number
@ -92,7 +91,7 @@ export const authClient = createAuthClient({
'Content-Type': 'application/json', 'Content-Type': 'application/json',
// x-ownerid: 商户ID如果后端需要 // x-ownerid: 商户ID如果后端需要
// 如果 MERCHANT_ID 为空,则不添加此 header // 如果 MERCHANT_ID 为空,则不添加此 header
...(MERCHANT_ID && { 'x-ownerid': MERCHANT_ID }), ...(OWNER_ID && { 'x-ownerid': OWNER_ID }),
}, },
auth: { auth: {
type: 'Bearer', type: 'Bearer',

View File

@ -7,7 +7,8 @@
"changePassword": "Change Password", "changePassword": "Change Password",
"language": "Language", "language": "Language",
"languageSwitch": "Language: 中文", "languageSwitch": "Language: 中文",
"languageSwitchEn": "Language: English" "languageSwitchEn": "Language: English",
"logout": "Logout"
}, },
"changePassword": { "changePassword": {
"title": "Change Password", "title": "Change Password",

View File

@ -7,7 +7,8 @@
"changePassword": "修改密码", "changePassword": "修改密码",
"language": "语言", "language": "语言",
"languageSwitch": "语言: 中文", "languageSwitch": "语言: 中文",
"languageSwitchEn": "Language: English" "languageSwitchEn": "Language: English",
"logout": "退出登录"
}, },
"changePassword": { "changePassword": {
"title": "修改密码", "title": "修改密码",