17 lines
453 B
TypeScript
17 lines
453 B
TypeScript
import 'server-only'
|
|
|
|
import { cookies } from 'next/headers'
|
|
import { decrypt } from '@/app/_lib/session'
|
|
import { redirect } from 'next/navigation'
|
|
import { cache } from 'react'
|
|
|
|
export const verifySession = cache(async () => {
|
|
const cookie = (await cookies()).get('session')?.value
|
|
const session = await decrypt(cookie)
|
|
|
|
if (!session?.userId) {
|
|
redirect('/admin/login')
|
|
}
|
|
|
|
return { isAuth: true, userId: session.userId }
|
|
}) |