-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathauth.ts
59 lines (55 loc) · 1.55 KB
/
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
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
58
59
import NextAuth from 'next-auth';
import Google from 'next-auth/providers/google';
import Kakao from 'next-auth/providers/kakao';
import Naver from 'next-auth/providers/naver';
export const { auth, handlers, signIn, signOut, unstable_update } = NextAuth({
providers: [
Naver({
clientId: process.env.NAVER_CLIENT_ID || '',
clientSecret: process.env.NAVER_CLIENT_SECRET || '',
async profile(profile: any) {
const data = profile.response;
return {
id: data.id,
email: data.email,
provider: 'naver',
};
},
}),
Kakao({
clientId: process.env.KAKAO_CLIENT_ID || '',
clientSecret: process.env.KAKAO_CLIENT_SECRET || '',
async profile(profile: any) {
return {
id: profile.id,
email: profile.kakao_account.email,
provider: 'kakao',
};
},
}),
Google({
clientId: process.env.GOOGLE_CLIENT_ID || '',
clientSecret: process.env.GOOGLE_CLIENT_SECRET || '',
async profile(profile: any) {
return {
id: profile.sub,
email: profile.email,
provider: 'google',
};
},
}),
],
callbacks: {
jwt: async ({ token, user, trigger, session }: any) => {
if (trigger === 'update' && session) {
return { ...token, ...session };
}
return { ...token, ...user };
},
session: async ({ session, token }: any) => {
session.user.uid = token.id;
session.user.provider = token.provider;
return session;
},
},
});