Skip to content
Snippets Groups Projects
route.ts 401 B
Newer Older
Yusuf Akgül's avatar
Yusuf Akgül committed
import { authOptions } from '@/lib/auth'
Omar Kasbah's avatar
Omar Kasbah committed
import { getServerSession } from 'next-auth/next'
import { NextResponse } from 'next/server'

Yusuf Akgül's avatar
Yusuf Akgül committed
export async function GET() {
Omar Kasbah's avatar
Omar Kasbah committed
    const session = await getServerSession(authOptions)

    if (!session) {
Yusuf Akgül's avatar
Yusuf Akgül committed
        return new NextResponse(JSON.stringify({ error: 'unauthorized' }), { status: 401 })
Omar Kasbah's avatar
Omar Kasbah committed
    }

    return NextResponse.json({ authenticated: !!session })
}