-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathauth.ts
27 lines (24 loc) · 966 Bytes
/
auth.ts
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
import NextAuth from "next-auth";
import GitHub from "next-auth/providers/github";
export const { handlers, signIn, signOut, auth } = NextAuth({
providers: [
GitHub({ clientId: process.env.GITHUB_ID, clientSecret: process.env.GITHUB_SECRET }),
],
secret: process.env.NEXTAUTH_SECRET,
callbacks: {
async signIn({ user, account, profile, email, credentials }) {
// Allowed email or email domain string
const allowedEmail = process.env.ALLOWED_EMAIL;
// Check if the user's email matches the allowed email
if (user?.email === allowedEmail || !allowedEmail) {
return true;
}
// If not, reject the sign-in
return "/api/auth/error?error=AccessDenied";
},
authorized: async ({ auth }) => {
// Logged in users are authenticated, otherwise redirect to login page
return !!auth;
},
},
});