Move to clerk
This commit is contained in:
parent
cd340320b7
commit
567b0ac313
18 changed files with 550 additions and 178 deletions
|
|
@ -4,6 +4,7 @@ import { revalidatePath } from 'next/cache'
|
|||
import { kv } from '@vercel/kv'
|
||||
|
||||
import { type Chat } from '@/lib/types'
|
||||
import { currentUser } from '@clerk/nextjs'
|
||||
|
||||
export async function getChats(userId?: string | null) {
|
||||
if (!userId) {
|
||||
|
|
@ -40,24 +41,19 @@ export async function getChat(id: string, userId: string) {
|
|||
return chat
|
||||
}
|
||||
|
||||
export async function removeChat({
|
||||
id,
|
||||
path,
|
||||
userId
|
||||
}: {
|
||||
id: string
|
||||
userId: string
|
||||
path: string
|
||||
}) {
|
||||
// @todo next-auth@v5 doesn't work in server actions yet
|
||||
// const session = await auth();
|
||||
export async function removeChat({ id, path }: { id: string; path: string }) {
|
||||
const user = await currentUser()
|
||||
|
||||
if (!user) {
|
||||
throw new Error('Unauthorized')
|
||||
}
|
||||
|
||||
const uid = await kv.hget<string>(`chat:${id}`, 'userId')
|
||||
if (uid !== userId) {
|
||||
if (uid !== user.id) {
|
||||
throw new Error('Unauthorized')
|
||||
}
|
||||
await kv.del(`chat:${id}`)
|
||||
await kv.zrem(`user:chat:${userId}`, `chat:${id}`)
|
||||
await kv.zrem(`user:chat:${user.id}`, `chat:${id}`)
|
||||
|
||||
revalidatePath('/')
|
||||
revalidatePath('/chat/[id]')
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue