mirror of
https://github.com/penxio/penx.git
synced 2026-04-19 03:03:06 -04:00
feat: add test api
This commit is contained in:
@@ -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)
|
||||
|
||||
|
||||
16
apps/web/app/api/hello/route.ts
Normal file
16
apps/web/app/api/hello/route.ts
Normal 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 })
|
||||
}
|
||||
Reference in New Issue
Block a user