tldraw/apps/www/pages/api/auth/[...nextauth].ts

40 lines
1 KiB
TypeScript
Raw Normal View History

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