From 37a4a2f807f80d46ad975475afe9e1cdc64e0619 Mon Sep 17 00:00:00 2001 From: imeepos Date: Tue, 13 Jan 2026 16:25:49 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E6=88=90=E5=8A=9F=E5=AF=B9=E6=8E=A5?= =?UTF-8?q?=E7=99=BB=E5=BD=95=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 2 +- components/blocks/AuthForm.tsx | 49 +++++++++++++++++++++------------- lib/auth.ts | 2 +- tmpclaude-4100-cwd | 1 - 4 files changed, 32 insertions(+), 22 deletions(-) delete mode 100644 tmpclaude-4100-cwd diff --git a/.gitignore b/.gitignore index f8c6c2e..904443f 100644 --- a/.gitignore +++ b/.gitignore @@ -8,7 +8,7 @@ node_modules/ dist/ web-build/ expo-env.d.ts - +tmpclaude-* # Native .kotlin/ *.orig.* diff --git a/components/blocks/AuthForm.tsx b/components/blocks/AuthForm.tsx index 0d5ad59..cecc403 100644 --- a/components/blocks/AuthForm.tsx +++ b/components/blocks/AuthForm.tsx @@ -1,19 +1,15 @@ import React, { useState } from "react"; -import { View, TextInput, ActivityIndicator } from "react-native"; import { useTranslation } from "react-i18next"; +import { ActivityIndicator, TextInput } from "react-native"; +import { authClient, setAuthToken, useSession } from "../../lib/auth"; +import { Block } from "../ui"; import { Button } from "../ui/button"; import Text from "../ui/Text"; -import { authClient, useSession } from "../../lib/auth"; -import { Block } from "../ui"; type AuthMode = "login" | "register"; -type AuthResponse = { data: unknown; error: { message: string; code?: string } | null }; -type SignInFn = (params: { username: string; password: string }) => Promise; -type SignUpFn = (params: { email: string; password: string; name: string }) => Promise; - -const signIn = authClient.signIn as unknown as { username: SignInFn }; -const signUp = authClient.signUp as unknown as { email: SignUpFn }; +const signIn = authClient.signIn +const signUp = authClient.signUp interface AuthFormProps { mode?: AuthMode; @@ -60,17 +56,31 @@ export function AuthForm({ mode = "login", onSuccess, onModeChange }: AuthFormPr try { if (isLogin) { - const res = await signIn.username({ username, password }); - if (res.error) { - setError(getErrorMessage(res.error)); - return; - } + await signIn.username({ username, password }, { + onSuccess: async (ctx) => { + const authToken = ctx.response.headers.get('set-auth-token') + if (authToken) { + setAuthToken(authToken) + } + }, + onError: (ctx) => { + setError(getErrorMessage(ctx.error)); + console.error(`[LOGIN] username login error`, ctx) + }, + }); } else { - const res = await signUp.email({ email, password, name: username }); - if (res.error) { - setError(getErrorMessage(res.error)); - return; - } + await signUp.email({ email, password, name: username }, { + onSuccess: async (ctx) => { + const authToken = ctx.response.headers.get('set-auth-token') + if (authToken) { + setAuthToken(authToken) + } + }, + onError: (ctx) => { + setError(getErrorMessage(ctx.error)); + console.error(`[LOGIN] username login error`, ctx) + }, + }); } onSuccess?.(); } catch (e: unknown) { @@ -158,3 +168,4 @@ export function AuthForm({ mode = "login", onSuccess, onModeChange }: AuthFormPr } export { useSession }; + diff --git a/lib/auth.ts b/lib/auth.ts index 0fe2898..655dabb 100644 --- a/lib/auth.ts +++ b/lib/auth.ts @@ -1,6 +1,5 @@ import 'reflect-metadata' -import Constants from 'expo-constants' import { expoClient } from '@better-auth/expo/client' import { createSkerClientPlugin } from '@repo/sdk' import { @@ -13,6 +12,7 @@ import { 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' diff --git a/tmpclaude-4100-cwd b/tmpclaude-4100-cwd deleted file mode 100644 index 71505f0..0000000 --- a/tmpclaude-4100-cwd +++ /dev/null @@ -1 +0,0 @@ -/c/Users/imeep/Desktop/shopify/expo-popcore-app