chatbot-template/auth.ts

37 lines
647 B
TypeScript
Raw Normal View History

2023-06-16 11:49:14 -04:00
import NextAuth from 'next-auth'
import GitHub from 'next-auth/providers/github'
2023-06-20 15:35:44 +02:00
declare module 'next-auth' {
interface Session {
user: {
/** The user's id. */
id: string
}
}
}
2023-06-16 11:49:14 -04:00
export const {
handlers: { GET, POST },
auth,
CSRF_experimental
} = NextAuth({
2023-06-20 15:35:44 +02:00
// @ts-expect-error
2023-06-16 11:49:14 -04:00
providers: [GitHub],
callbacks: {
jwt: async ({ token, profile }) => {
2023-06-20 15:35:44 +02:00
if (profile) {
2023-06-16 11:49:14 -04:00
token.id = profile.id
token.image = profile.picture
}
return token
}
2023-06-16 13:30:27 -04:00
// @TODO
2023-06-16 12:58:52 -04:00
// authorized({ request, auth }) {
// return !!auth?.user
// }
2023-06-16 11:49:14 -04:00
},
pages: {
signIn: '/sign-in'
}
})