-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathauth.config.ts
More file actions
45 lines (39 loc) · 1.03 KB
/
Copy pathauth.config.ts
File metadata and controls
45 lines (39 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
34
35
36
37
38
39
40
41
42
43
44
45
import { NextAuthConfig } from "next-auth";
import Github from "next-auth/providers/github";
import Google from "next-auth/providers/google";
export const authConfig = {
providers: [
Github({
clientId: process.env.GITHUB_CLIENT_ID,
clientSecret: process.env.GITHUB_CLIENT_SECRET,
}),
Google({
clientId: process.env.GOOGLE_CLIENT_ID,
clientSecret: process.env.GOOGLE_CLIENT_SECRET,
}),
],
pages: {
signIn: "/login",
error: "auth/error",
},
callbacks: {
async session({ session, token }) {
if (token?.sub && token?.role) {
session.user = {
...session.user,
id: token.sub,
role: token.role as string
};
}
return session;
},
async jwt({ token, user }) {
// On initial sign in, user object is available
if (user) {
token.role = user.role as string;
}
// For subsequent requests without user object, keep existing token data
return token;
},
},
} satisfies NextAuthConfig;