Update next-auth

This commit is contained in:
Jared Palmer 2023-06-16 12:03:09 -04:00
parent 187b55aad7
commit fef709a21d
6 changed files with 28 additions and 10 deletions

View file

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

View file

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

View file

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