feat: add test api

This commit is contained in:
0xzio
2025-05-10 20:42:07 +08:00
parent ea6c6c2f20
commit b9ccd2c4ee
2 changed files with 48 additions and 32 deletions

View File

@@ -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)

View File

@@ -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 })
}