generated from jhackett1/railsy-nextjs-prisma-example
-
Notifications
You must be signed in to change notification settings - Fork 0
/
[...nextauth].js
46 lines (40 loc) · 1.15 KB
/
[...nextauth].js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import NextAuth from "next-auth"
import Providers from "next-auth/providers"
import Adapters from "next-auth/adapters"
import prisma from "../../../lib/prisma"
const authHandler = (req, res) =>
NextAuth(req, res, {
providers: [
Providers.Google({
clientId: process.env.GOOGLE_CLIENT_ID,
clientSecret: process.env.GOOGLE_CLIENT_SECRET,
}),
],
pages: {
signIn: "/auth/signin",
},
callbacks: {
// include extra info in the session object
async session(session, user) {
session.user.id = user.id
session.user.useSignature = user.useSignature
session.user.signature = user.signature
return session
},
// restrict to hackney accounts
async signIn(user, account, profile) {
if (
account.provider === "google" &&
profile.verified_email === true &&
profile.email.endsWith(process.env.ALLOWED_DOMAIN)
) {
return true
} else {
return false
}
},
},
adapter: Adapters.Prisma.Adapter({ prisma }),
secret: process.env.SESSION_SECRET,
})
export default authHandler