forked from vercel/ai-chatbot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathauth.ts
27 lines (24 loc) · 755 Bytes
/
auth.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
import { NextResponse } from 'next/server'
import NextAuth from '@auth/nextjs'
import GitHub from '@auth/nextjs/providers/github'
export const {
handlers: { GET, POST },
auth,
CSRF_experimental
} = NextAuth({
// @ts-ignore
providers: [GitHub],
session: { strategy: 'jwt' },
async authorized({ request, auth }: any) {
const url = request.nextUrl
if (request.method === 'POST') {
const { authToken } = (await request.json()) ?? {}
// If the request has a valid auth token, it is authorized
const valid = true
if (valid) return true
return NextResponse.json('Invalid auth token', { status: 401 })
}
// Logged in users are authenticated, otherwise redirect to login page
return !!auth
}
})