登录-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

View File

@@ -17,6 +17,7 @@ import { getQueryParam } from '../lib/utils'
import BLOG from '@/blog.config'
import ExternalPlugins from '@/components/ExternalPlugins'
import GlobalHead from '@/components/GlobalHead'
import { ClerkProvider } from '@clerk/nextjs'
/**
* App挂载DOM 入口文件
@@ -47,13 +48,15 @@ const MyApp = ({ Component, pageProps }) => {
)
return (
<GlobalContextProvider {...pageProps}>
<GLayout {...pageProps}>
<GlobalHead {...pageProps} />
<Component {...pageProps} />
</GLayout>
<ExternalPlugins {...pageProps} />
</GlobalContextProvider>
<ClerkProvider>
<GlobalContextProvider {...pageProps}>
<GLayout {...pageProps}>
<GlobalHead {...pageProps} />
<Component {...pageProps} />
</GLayout>
<ExternalPlugins {...pageProps} />
</GlobalContextProvider>
</ClerkProvider>
)
}

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

View File

@@ -1,6 +1,8 @@
// import BLOG from '@/blog.config'
import BLOG from '@/blog.config'
import { siteConfig } from '@/lib/config'
import { getGlobalData } from '@/lib/db/getSiteData'
// import { getGlobalData } from '@/lib/db/getSiteData'
import { getLayoutByTheme } from '@/themes/theme'
import { useRouter } from 'next/router'
@@ -37,4 +39,15 @@ export async function getStaticProps(req) {
}
}
/**
* catch-all route for clerk
* @returns
*/
export async function getStaticPaths() {
return {
paths: [],
fallback: true
}
}
export default SignIn

View File

@@ -37,4 +37,15 @@ export async function getStaticProps(req) {
}
}
/**
* catch-all route for clerk
* @returns
*/
export async function getStaticPaths() {
return {
paths: [],
fallback: true
}
}
export default SignUp