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
|
|
|
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 },
|
2023-11-26 18:30:48 -06:00
|
|
|
auth
|
2023-06-16 11:49:14 -04:00
|
|
|
} = 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-11-27 22:14:06 +01:00
|
|
|
token.id = profile.id
|
2023-08-27 18:44:29 +03:00
|
|
|
token.image = profile.avatar_url || profile.picture
|
2023-06-16 11:49:14 -04:00
|
|
|
}
|
|
|
|
|
return token
|
2023-06-22 10:37:35 -07:00
|
|
|
},
|
2023-11-26 18:30:48 -06:00
|
|
|
session: ({ session, token }) => {
|
|
|
|
|
if (session?.user && token?.id) {
|
2023-11-27 22:14:06 +01:00
|
|
|
session.user.id = String(token.id)
|
2023-11-26 18:30:48 -06:00
|
|
|
}
|
|
|
|
|
return session
|
|
|
|
|
},
|
2023-06-22 10:37:35 -07:00
|
|
|
authorized({ auth }) {
|
2023-07-05 12:00:46 -04:00
|
|
|
return !!auth?.user // this ensures there is a logged in user for -every- request
|
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: {
|
2023-07-05 12:00:46 -04:00
|
|
|
signIn: '/sign-in' // overrides the next-auth default signin page https://authjs.dev/guides/basics/pages
|
2023-06-27 20:03:01 +02:00
|
|
|
}
|
2023-11-26 18:30:48 -06:00
|
|
|
})
|