chatbot-template/auth.ts

40 lines
825 B
TypeScript
Raw Normal View History

2023-06-21 14:29:19 -07: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-21 14:29:19 -07:00
declare module 'next-auth' {
/**
* Returned by `useSession`, `getSession` and received as a prop on the `SessionProvider` React Context
*/
interface Session {
user: {
/** The user's postal address. */
id: string
} & DefaultSession['user']
}
}
2023-06-16 11:49:14 -04:00
export const {
handlers: { GET, POST },
auth,
CSRF_experimental
} = NextAuth({
2023-06-21 11:17:59 -07:00
// @ts-ignore
2023-06-16 11:49:14 -04:00
providers: [GitHub],
callbacks: {
jwt: async ({ token, profile }) => {
2023-06-21 14:19:13 -07:00
if (profile?.id) {
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'
}
})