-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
173 additions
and
52 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
/* eslint-disable react/prop-types */ | ||
|
||
'use client'; | ||
|
||
import React from 'react'; | ||
import { SessionProvider } from 'next-auth/react'; | ||
|
||
export default function AuthSession({ children }) { | ||
return <SessionProvider>{children}</SessionProvider>; | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
/* eslint-disable no-console */ | ||
|
||
import bcrypt from 'bcryptjs'; | ||
import NextAuth from 'next-auth'; | ||
import CredentialsProvider from 'next-auth/providers/credentials'; | ||
import { PrismaAdapter } from '@auth/prisma-adapter'; | ||
import { PrismaClient } from '@prisma/client'; | ||
|
||
const prisma = new PrismaClient(); | ||
|
||
const handler = NextAuth({ | ||
adapter: PrismaAdapter(prisma), | ||
providers: [ | ||
CredentialsProvider({ | ||
name: 'Credentials', | ||
credentials: { | ||
email: { | ||
label: 'Email', | ||
type: 'text', | ||
placeholder: '이메일 주소 입력', | ||
}, | ||
password: { | ||
label: 'Password', | ||
type: 'password', | ||
placeholder: '비밀번호 입력', | ||
}, | ||
}, | ||
// 승인 | ||
async authorize(credentials) { | ||
if (!credentials?.email || !credentials?.password) { | ||
return null; | ||
} | ||
// Prisma를 사용하여 유저 정보를 가져옴 | ||
const user = await prisma.user.findUnique({ | ||
where: { email: credentials.email }, | ||
}); | ||
|
||
console.log(user); | ||
|
||
if (!user) { | ||
return null; | ||
} | ||
const isCorrectPassword = await bcrypt.compare( | ||
credentials.password, | ||
user.password, | ||
); | ||
|
||
if (!isCorrectPassword) { | ||
return null; | ||
} | ||
console.log('로그인 완료'); | ||
return user; | ||
}, | ||
}), | ||
], | ||
session: { | ||
strategy: 'jwt', | ||
}, | ||
callbacks: { | ||
async jwt({ token, user, session }) { | ||
if (user) { | ||
return { | ||
...token, | ||
id: user.id, | ||
}; | ||
} | ||
return token; | ||
}, | ||
async session({ session, token, user }) { | ||
return { | ||
...session, | ||
user: { | ||
...session.user, | ||
id: token.id, | ||
}, | ||
}; | ||
}, | ||
}, | ||
secret: process.env.NEXTAUTH_SECRET, | ||
}); | ||
|
||
export { handler as GET, handler as POST }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters