chatbot-template/auth.ts

36 lines
677 B
TypeScript
Raw Normal View History

2023-06-27 20:03:01 +02:00
import NextAuth, { type DefaultSession } from 'next-auth'
2023-06-16 11:49:14 -04:00
import GitHub from 'next-auth/providers/github'
2023-06-27 20:03:01 +02:00
import { NextResponse } from 'next/server'
2023-06-16 11:49:14 -04:00
2023-06-27 20:03:01 +02:00
declare module 'next-auth' {
interface Session {
user: {
/** The user's id. */
id: string
} & DefaultSession['user']
}
}
2023-06-22 11:02:20 -07:00
2023-06-16 11:49:14 -04:00
export const {
handlers: { GET, POST },
auth,
CSRF_experimental
} = NextAuth({
2023-06-27 20:03:01 +02:00
providers: [GitHub],
2023-06-16 11:49:14 -04:00
callbacks: {
2023-06-27 20:03:01 +02:00
jwt({ token, profile }) {
if (profile) {
2023-06-16 11:49:14 -04:00
token.id = profile.id
token.image = profile.picture
}
return token
2023-06-22 10:37:35 -07:00
},
authorized({ auth }) {
return !!auth?.user
2023-06-27 20:03:01 +02:00
}
2023-06-16 11:49:14 -04:00
},
2023-06-27 20:03:01 +02:00
pages: {
signIn: '/sign-in'
}
2023-06-16 11:49:14 -04:00
})