์์ ํฌ์ธํธ๋ 2๊ฐ์ด๋ค.
credentials์ type์ ๋ช ์, ๋ก๊ทธ์ธ ์ฑ๊ณตํ๊ณ return ๋๋ user ๊ฐ์ any๋ก ๋ฐํ
import bcrypt from "bcrypt";
import NextAuth, { AuthOptions } from "next-auth";
import CredentialsProvider from "next-auth/providers/credentials";
import prismadb from "@/app/lib/prisma";
import { PrismaAdapter } from "@auth/prisma-adapter";
export const authOptions: AuthOptions = {
providers: [
CredentialsProvider({
name: "credentials",
// ์๋ credentials์ ๊ธฐ๋ณธ ํฌ๋งท์ด ์ค์ ๋์ด์ผํ๋ค.
credentials: {
email: {},
password: {},
},
async authorize(credentials) {
// User
console.log(credentials);
if (!credentials?.email || !credentials?.password) {
throw new Error("ID&PW mismatch");
}
const user = await prismadb.user.findUnique({
where: {
email: credentials.email,
},
});
if (!user) {
throw new Error("Contact Admin");
}
const isCorrectPassword = await bcrypt.compare(
credentials.password,
user.hashedPassword,
);
if (!isCorrectPassword) {
throw new Error("ID&PW mismatch");
}
// as any๋ก ๋ฐํํด์ผ ์ค๋ฅ๊ฐ ์๋ฌ๋ค.
return user as any;
},
}),
],
session: {
strategy: "jwt",
},
pages: {
signIn: "/",
},
secret: process.env.NEXTAUTH_SECRET,
};
const handler = NextAuth(authOptions);
export { handler as GET, handler as POST };
'๐ํ๋ก๊ทธ๋๋ฐ > Next.js' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[Next.js] npm run start prisma findMany ๊ฐฑ์ ์๋ ๋ (0) | 2024.08.02 |
---|---|
[Next.js] ๋ฆฌ์ํธ ํ ์ด๋ธ CSV ์ ์ฅ ๊ตฌํ(feat. Shadcn) (0) | 2024.06.21 |
[Nextjs] api return ๊ฐ ๊ฐฑ์ ์๋๋ ์ด์ (0) | 2023.12.04 |
[nextjs] ์์ ํ์ผ ๋ค์ด๋ก๋ (1) | 2023.11.27 |
[Nextjs] ํ์ผ ์ ๋ก๋(file upload) (0) | 2023.11.22 |