From b9ccd2c4eefac9f8bf31d712b1308dcba6cc773d Mon Sep 17 00:00:00 2001 From: 0xzio Date: Sat, 10 May 2025 20:42:07 +0800 Subject: [PATCH] feat: add test api --- .../components/Login/LoginDrawerContent.tsx | 64 +++++++++---------- apps/web/app/api/hello/route.ts | 16 +++++ 2 files changed, 48 insertions(+), 32 deletions(-) create mode 100644 apps/web/app/api/hello/route.ts diff --git a/apps/mobile/components/Login/LoginDrawerContent.tsx b/apps/mobile/components/Login/LoginDrawerContent.tsx index a67bfea5..ae059e45 100644 --- a/apps/mobile/components/Login/LoginDrawerContent.tsx +++ b/apps/mobile/components/Login/LoginDrawerContent.tsx @@ -28,40 +28,40 @@ export function LoginDrawerContent({ setVisible }: Props) { const [error, setError] = useState({}) const [session, setSession] = useState({}) async function onLogin() { - const res = (await SocialLogin.login({ - provider: 'google', - options: { - scopes: ['email', 'openid', 'profile'], - }, - })) as any as MobileGoogleLoginInfo - // alert(JSON.stringify(res)) - // handle the response. popoutStore is specific to my app - console.log('======res:', res) - - setJson(res.result) - - fetch('https://jsonplaceholder.typicode.com/todos/1') - .then((response) => response.json()) - .then((json) => console.log(json)) - - const sites = await localDB.site.toArray() - const site = sites.find((s) => !s.isRemote) - - const session = await login({ - type: 'penx-google', - accessToken: res.result.accessToken.token as string, - userId: site?.userId!, - ref: '', - }) - - console.log('======session:', session) - - setSession(session) - await set('SESSION', session) - queryClient.setQueryData(['SESSION'], session) - setVisible(false) + const todo = await fetch( + 'https://jsonplaceholder.typicode.com/todos/1', + ).then((response) => response.json()) + console.log('todo.........>>>>:', todo) try { + const res = (await SocialLogin.login({ + provider: 'google', + options: { + scopes: ['email', 'openid', 'profile'], + }, + })) as any as MobileGoogleLoginInfo + // alert(JSON.stringify(res)) + // handle the response. popoutStore is specific to my app + console.log('======res:', res) + + setJson(res.result) + + const sites = await localDB.site.toArray() + const site = sites.find((s) => !s.isRemote) + + const session = await login({ + type: 'penx-google', + accessToken: res.result.accessToken.token as string, + userId: site?.userId!, + ref: '', + }) + + console.log('======session:', session) + + setSession(session) + await set('SESSION', session) + queryClient.setQueryData(['SESSION'], session) + setVisible(false) } catch (error) { console.log('=========error:', error) diff --git a/apps/web/app/api/hello/route.ts b/apps/web/app/api/hello/route.ts new file mode 100644 index 00000000..92774a38 --- /dev/null +++ b/apps/web/app/api/hello/route.ts @@ -0,0 +1,16 @@ +import { NextRequest } from 'next/server' + +const headers = { + 'Access-Control-Allow-Origin': '*', + 'Access-Control-Allow-Methods': 'POST, OPTIONS', + 'Access-Control-Allow-Headers': 'Content-Type, Authorization', +} + +// login +export async function POST(req: NextRequest) { + return Response.json({ foo: 'bar' }, { headers }) +} + +export async function GET() { + return Response.json({ hello: 'world' }, { headers }) +}