Update next-auth
This commit is contained in:
parent
187b55aad7
commit
fef709a21d
6 changed files with 28 additions and 10 deletions
|
|
@ -44,7 +44,7 @@ export async function getChat(id: string, userId: string) {
|
|||
}
|
||||
|
||||
export async function removeChat({ id, path }: { id: string; path: string }) {
|
||||
const session = await auth<{ stuff: string }>()
|
||||
const session = await auth()
|
||||
|
||||
if (!session) {
|
||||
throw new Error('Unauthorized')
|
||||
|
|
|
|||
|
|
@ -1,9 +1,8 @@
|
|||
import { kv } from '@vercel/kv'
|
||||
import { OpenAIStream, StreamingTextResponse } from 'ai-connector'
|
||||
import { Configuration, OpenAIApi } from 'openai-edge'
|
||||
|
||||
import { nanoid } from '@/lib/utils'
|
||||
import { currentUser } from '@clerk/nextjs'
|
||||
import { auth } from '@/auth'
|
||||
|
||||
export const runtime = 'edge'
|
||||
|
||||
|
|
@ -18,8 +17,8 @@ if (!process.env.OPENAI_API_KEY) {
|
|||
}
|
||||
|
||||
export async function POST(req: Request) {
|
||||
const user = await currentUser()
|
||||
if (user == null) {
|
||||
const session = await auth()
|
||||
if (session == null) {
|
||||
return new Response('Unauthorized', { status: 401 })
|
||||
}
|
||||
|
||||
|
|
@ -40,7 +39,7 @@ export async function POST(req: Request) {
|
|||
const stream = OpenAIStream(res, {
|
||||
async onCompletion(completion) {
|
||||
const title = json.messages[0].content.substring(0, 100)
|
||||
const userId = user.id
|
||||
const userId = session.user.id
|
||||
const id = json.id ?? nanoid()
|
||||
const createdAt = Date.now()
|
||||
const path = `/chat/${id}`
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
import { type Metadata } from 'next'
|
||||
import { auth } from '@clerk/nextjs'
|
||||
import { auth } from '@/auth'
|
||||
|
||||
import { Chat } from '@/components/chat'
|
||||
import { getChat } from '@/app/actions'
|
||||
|
|
|
|||
7
auth.ts
7
auth.ts
|
|
@ -5,16 +5,23 @@ export const {
|
|||
handlers: { GET, POST },
|
||||
auth,
|
||||
CSRF_experimental
|
||||
// @ts-ignore
|
||||
} = NextAuth({
|
||||
// @ts-ignore
|
||||
providers: [GitHub],
|
||||
callbacks: {
|
||||
// @ts-ignore
|
||||
jwt: async ({ token, profile }) => {
|
||||
if (profile?.id) {
|
||||
token.id = profile.id
|
||||
token.image = profile.picture
|
||||
}
|
||||
return token
|
||||
},
|
||||
// @ts-ignore
|
||||
authorized({ request, auth }) {
|
||||
if (!request.nextUrl.pathname.startsWith('/share/')) return true
|
||||
return !!auth?.user
|
||||
}
|
||||
},
|
||||
pages: {
|
||||
|
|
|
|||
10
next-auth.d.ts
vendored
10
next-auth.d.ts
vendored
|
|
@ -1,7 +1,13 @@
|
|||
import NextAuth, { DefaultSession } from 'next-auth'
|
||||
|
||||
declare module 'next-auth' {
|
||||
/**
|
||||
* Returned by `useSession`, `getSession` and received as a prop on the `SessionProvider` React Context
|
||||
*/
|
||||
interface Session {
|
||||
user: {
|
||||
id: string
|
||||
}
|
||||
/** The user's postal address. */
|
||||
address: string
|
||||
} & DefaultSession['user']
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -24,6 +24,12 @@
|
|||
],
|
||||
"strictNullChecks": true
|
||||
},
|
||||
"include": ["next-env.d.ts", "**/*.ts", "**/*.tsx", ".next/types/**/*.ts"],
|
||||
"include": [
|
||||
"next-env.d.ts",
|
||||
"next-auth.d.ts",
|
||||
"**/*.ts",
|
||||
"**/*.tsx",
|
||||
".next/types/**/*.ts"
|
||||
],
|
||||
"exclude": ["node_modules"]
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue