登录-clerk方案

This commit is contained in:
tangly1024.com
2024-06-17 17:03:42 +08:00
parent be048bb51e
commit b0ee510624
14 changed files with 421 additions and 93 deletions

18
pages/api/user.ts Normal file
View File

@@ -0,0 +1,18 @@
import { getAuth } from '@clerk/nextjs/server'
import type { NextApiRequest, NextApiResponse } from 'next'
/**
* clerk身份测试
* @param req
* @param res
* @returns
*/
export default function handler(req: NextApiRequest, res: NextApiResponse) {
const user = getAuth(req)
const { userId } = user
if (!userId) {
return res.status(401).json({ error: 'Unauthorized' })
}
// retrieve data from your database
res.status(200).json({ userId })
}