2021-11-26 15:14:10 +00:00
|
|
|
import { isSponsoringMe } from 'utils/isSponsoringMe'
|
|
|
|
import type { NextApiHandler, NextApiRequest, NextApiResponse } from 'next'
|
2021-09-04 12:18:44 +00:00
|
|
|
import NextAuth from 'next-auth'
|
|
|
|
import Providers from 'next-auth/providers'
|
|
|
|
|
|
|
|
export default function Auth(
|
|
|
|
req: NextApiRequest,
|
|
|
|
res: NextApiResponse
|
|
|
|
): ReturnType<NextApiHandler> {
|
|
|
|
return NextAuth(req, res, {
|
|
|
|
providers: [
|
|
|
|
Providers.GitHub({
|
|
|
|
clientId: process.env.GITHUB_ID,
|
|
|
|
clientSecret: process.env.GITHUB_SECRET,
|
|
|
|
scope: 'read:user',
|
|
|
|
}),
|
|
|
|
],
|
|
|
|
callbacks: {
|
|
|
|
async redirect(url, baseUrl) {
|
|
|
|
return baseUrl
|
|
|
|
},
|
2021-09-08 10:39:22 +00:00
|
|
|
async signIn(user, account, profile: { login?: string }) {
|
2021-11-26 15:14:10 +00:00
|
|
|
if (profile?.login) {
|
|
|
|
const canLogin = await isSponsoringMe(profile.login)
|
2021-09-04 12:18:44 +00:00
|
|
|
|
2021-11-26 15:14:10 +00:00
|
|
|
if (canLogin) {
|
|
|
|
return canLogin
|
|
|
|
}
|
2021-09-04 12:18:44 +00:00
|
|
|
}
|
2021-11-26 15:14:10 +00:00
|
|
|
|
|
|
|
return '/'
|
2021-09-04 12:18:44 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|