forked from FRONT-END-BOOTCAMP-PLUS-4/room-to-be
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathauth.ts
More file actions
48 lines (45 loc) · 1.22 KB
/
auth.ts
File metadata and controls
48 lines (45 loc) · 1.22 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
46
47
48
import { PrismaAdapter } from '@auth/prisma-adapter';
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';
import { prisma } from './backend/infra/db/prisma/prismaClient';
export const { handlers, auth, signIn, signOut } = NextAuth({
adapter: PrismaAdapter(prisma),
session: { strategy: 'jwt' },
providers: [
Google,
Naver({
profile(profile) {
const name = profile.response.name || profile.response.nickname;
return {
id: profile.response.id,
name,
email: profile.response.email ?? '',
image: profile.response.profile_image ?? null,
};
},
}),
Kakao({
authorization: {
url: 'https://kauth.kakao.com/oauth/authorize',
params: {
scope: 'profile_nickname profile_image account_email',
prompt: 'login',
},
},
}),
],
callbacks: {
async jwt({ token, user }) {
if (user) {
token.id = user.id;
}
return token;
},
async session({ session, token }) {
session.user.id = token.id as string;
return session;
},
},
});