-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathauth.ts
More file actions
38 lines (34 loc) · 1012 Bytes
/
Copy pathauth.ts
File metadata and controls
38 lines (34 loc) · 1012 Bytes
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
import NextAuth from "next-auth";
import GitHub from "next-auth/providers/github";
export const { handlers, signIn, signOut, auth } = NextAuth({
providers: [
GitHub({
clientId: process.env.AUTH_GITHUB_ID,
clientSecret: process.env.AUTH_GITHUB_SECRET,
}),
],
callbacks: {
signIn: async ({ user }) => {
const allowedEmail = process.env.AUTH_ALLOWED_EMAIL;
// If allowedEmail is empty or undefined, log the issue
if (!allowedEmail) {
console.error("AUTH_ALLOWED_EMAIL environment variable is not set");
return false;
}
// Check if the user's email matches the allowed email
if (user.email !== allowedEmail) {
console.log(
`Email ${user.email} not authorized. Only ${allowedEmail} is allowed.`
);
return false;
}
return true;
},
},
session: {
strategy: "jwt",
},
secret: process.env.AUTH_SECRET,
trustHost: true,
debug: process.env.NODE_ENV === "development",
});