2021-12-22 00:14:38 +00:00
|
|
|
import { isSignedInUserSponsoringMe } from 'utils/github'
|
2021-11-26 15:14:10 +00:00
|
|
|
import type { NextApiHandler, NextApiRequest, NextApiResponse } from 'next'
|
2021-09-04 12:18:44 +00:00
|
|
|
import NextAuth from 'next-auth'
|
2021-12-22 00:14:38 +00:00
|
|
|
import GithubProvider from 'next-auth/providers/github'
|
2021-09-04 12:18:44 +00:00
|
|
|
|
|
|
|
export default function Auth(
|
|
|
|
req: NextApiRequest,
|
|
|
|
res: NextApiResponse
|
|
|
|
): ReturnType<NextApiHandler> {
|
|
|
|
return NextAuth(req, res, {
|
2021-12-22 00:14:38 +00:00
|
|
|
theme: {
|
|
|
|
colorScheme: 'light',
|
|
|
|
},
|
2021-09-04 12:18:44 +00:00
|
|
|
providers: [
|
2021-12-22 00:14:38 +00:00
|
|
|
GithubProvider({
|
2021-09-04 12:18:44 +00:00
|
|
|
clientId: process.env.GITHUB_ID,
|
|
|
|
clientSecret: process.env.GITHUB_SECRET,
|
2021-12-22 00:14:38 +00:00
|
|
|
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
|
|
// @ts-ignore
|
2021-09-04 12:18:44 +00:00
|
|
|
scope: 'read:user',
|
|
|
|
}),
|
|
|
|
],
|
2021-12-22 00:14:38 +00:00
|
|
|
secret: process.env.NEXTAUTH_SECRET,
|
2021-09-04 12:18:44 +00:00
|
|
|
callbacks: {
|
2021-12-22 00:14:38 +00:00
|
|
|
async redirect({ baseUrl }) {
|
2021-09-04 12:18:44 +00:00
|
|
|
return baseUrl
|
|
|
|
},
|
2021-12-22 00:14:38 +00:00
|
|
|
async signIn() {
|
|
|
|
return true
|
|
|
|
},
|
|
|
|
async session({ session, token, user }) {
|
|
|
|
if (token) {
|
|
|
|
session.isSponsor = await isSignedInUserSponsoringMe()
|
2021-09-04 12:18:44 +00:00
|
|
|
}
|
2021-12-22 00:14:38 +00:00
|
|
|
return session
|
2021-09-04 12:18:44 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|