forked from jaturapornchai/bcproxyai
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathauth.ts
More file actions
33 lines (32 loc) · 1.03 KB
/
Copy pathauth.ts
File metadata and controls
33 lines (32 loc) · 1.03 KB
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
import NextAuth from "next-auth";
import Google from "next-auth/providers/google";
import { isOwnerEmail } from "./src/lib/admin-emails";
export const { handlers, auth, signIn, signOut } = NextAuth({
providers: [
Google({
clientId: process.env.GOOGLE_CLIENT_ID,
clientSecret: process.env.GOOGLE_CLIENT_SECRET,
}),
],
session: { strategy: "jwt" },
trustHost: true,
pages: { signIn: "/login" },
callbacks: {
async signIn({ profile }) {
return Boolean(profile?.email_verified);
},
async jwt({ token, profile }) {
if (profile?.email) token.email = profile.email;
const email = typeof token.email === "string" ? token.email : "";
token.role = isOwnerEmail(email) ? "owner" : "viewer";
return token;
},
async session({ session, token }) {
if (session.user) {
session.user.email = (token.email as string | undefined) ?? session.user.email;
}
(session as { role?: string }).role = (token.role as string) ?? "viewer";
return session;
},
},
});