-
Notifications
You must be signed in to change notification settings - Fork 0
/
auth.config.ts
57 lines (54 loc) · 1.47 KB
/
auth.config.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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
import type { DefaultSession, NextAuthConfig } from 'next-auth';
import { JWT } from 'next-auth/jwt';
import GitHub from 'next-auth/providers/github';
declare module 'next-auth' {
interface User {
// Additional properties here:
role?: string;
}
interface Session extends DefaultSession {
/**
* By default, TypeScript merges new interface properties and overwrites existing ones.
* In this case, the default session user properties will be overwritten,
* with the new ones defined above. To keep the default session user properties,
* we need to add them back into the newly declared interface.
*/
user: DefaultSession['user'] & {
role?: string;
};
}
}
declare module 'next-auth/jwt' {
interface JWT {
role?: string;
}
}
export const authConfig = {
session: { strategy: 'jwt' },
providers: [
GitHub({
clientId: process.env.AUTH_GITHUB_ID,
clientSecret: process.env.AUTH_GITHUB_SECRET,
profile(profile) {
return {
image: profile.avatar_url,
role: profile.id === Number(process.env.GITHUB_ID) ? 'admin' : 'user',
};
},
}),
],
callbacks: {
jwt({ token, user }) {
if (user) {
token.role = user.role;
token.picture = user.image;
}
return token;
},
session({ session, token }) {
session.user.image = token.picture;
session.user.role = token.role;
return session;
},
},
} satisfies NextAuthConfig;