Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
node_modules/
.next/
.env
.env.local
.DS_Store
npm-debug.log*
yarn-debug.log*
yarn-error.log*
19 changes: 19 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
<<<<<<< HEAD
# 🐼 판다마켓 프로젝트

> _이 저장소는 판다마켓 프로젝트의 프론트엔드 코드를 관리하는 곳입니다. 프로젝트를 클론하여 개발 환경을 설정하고, 각 브랜치에서 해당 스프린트 미션을 수행해 주세요!_ 🛠️
Expand Down Expand Up @@ -48,3 +49,21 @@ _위 이미지는 판다마켓의 대표 이미지입니다._ 📸
---

본 프로젝트는 [코드잇](https://www.codeit.kr)의 소유이며, 교육 목적으로만 사용됩니다. © 2024 Codeit. All rights reserved.
=======
# React + Vite

This template provides a minimal setup to get React working in Vite with HMR and some ESLint rules.

Currently, two official plugins are available:

- [@vitejs/plugin-react](https://github.com/vitejs/vite-plugin-react/blob/main/packages/plugin-react) uses [Babel](https://babeljs.io/) for Fast Refresh
- [@vitejs/plugin-react-swc](https://github.com/vitejs/vite-plugin-react/blob/main/packages/plugin-react-swc) uses [SWC](https://swc.rs/) for Fast Refresh

## React Compiler

The React Compiler is not enabled on this template. To add it, see [this documentation](https://react.dev/learn/react-compiler/installation).

## Expanding the ESLint configuration

If you are developing a production application, we recommend using TypeScript with type-aware lint rules enabled. Check out the [TS template](https://github.com/vitejs/vite/tree/main/packages/create-vite/template-react-ts) for information on how to integrate TypeScript and [`typescript-eslint`](https://typescript-eslint.io) in your project.
>>>>>>> d825b2c (CSS 리팩토링 및 이미지 관리 구조 개선)
74 changes: 74 additions & 0 deletions app/api/auth/login/route.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
import { NextResponse, type NextRequest } from "next/server";
import { PrismaClient } from "@prisma/client";
import bcrypt from "bcryptjs";
import jwt from "jsonwebtoken";

const prisma = new PrismaClient();
const JWT_SECRET: string = process.env.JWT_SECRET || "dev-secret";

interface LoginRequestBody {
email: string;
password: string;
}

export async function POST(req: NextRequest) {
try {
const body = (await req.json()) as LoginRequestBody;
const { email, password } = body;

if (!email || !password) {
return NextResponse.json(
{ message: "이메일과 비밀번호는 필수입니다." },
{ status: 400 }
);
}

const user = await prisma.user.findUnique({
where: { email },
});

if (!user) {
return NextResponse.json(
{ message: "이메일 또는 비밀번호가 일치하지 않습니다." },
{ status: 401 }
);
}

const isValid = await bcrypt.compare(password, user.encryptedPassword);

if (!isValid) {
return NextResponse.json(
{ message: "이메일 또는 비밀번호가 일치하지 않습니다." },
{ status: 401 }
);
}

const accessToken = jwt.sign(
{
userId: user.id,
email: user.email,
nickname: user.nickname,
},
JWT_SECRET,
{ expiresIn: "7d" }
);

return NextResponse.json(
{
accessToken,
user: {
id: user.id,
email: user.email,
nickname: user.nickname,
},
},
{ status: 200 }
);
} catch (error) {
console.error("login API error:", error);
return NextResponse.json(
{ message: "로그인 중 서버 오류가 발생했습니다." },
{ status: 500 }
);
}
}
76 changes: 76 additions & 0 deletions app/api/auth/signup/route.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
import { NextResponse, type NextRequest } from "next/server";
import { PrismaClient } from "@prisma/client";
import bcrypt from "bcryptjs";
import jwt from "jsonwebtoken";

const prisma = new PrismaClient();
const JWT_SECRET: string = process.env.JWT_SECRET || "dev-secret";

interface SignUpRequestBody {
email: string;
nickname: string;
password: string;
}

export async function POST(req: NextRequest) {
try {
const body = (await req.json()) as SignUpRequestBody;
const { email, nickname, password } = body;

if (!email || !nickname || !password) {
return NextResponse.json(
{ message: "이메일, 닉네임, 비밀번호는 필수입니다." },
{ status: 400 }
);
}

const existingUser = await prisma.user.findUnique({
where: { email },
});

if (existingUser) {
return NextResponse.json(
{ message: "이미 사용 중인 이메일입니다." },
{ status: 409 }
);
}

const hashedPassword = await bcrypt.hash(password, 10);

const newUser = await prisma.user.create({
data: {
email,
nickname,
encryptedPassword: hashedPassword,
},
});

const accessToken = jwt.sign(
{
userId: newUser.id,
email,
nickname,
},
JWT_SECRET,
{ expiresIn: "7d" }
);

return NextResponse.json(
{
accessToken,
user: {
id: newUser.id,
email,
nickname,
},
},
{ status: 201 }
);
} catch (error) {
console.error("signUp API error:", error);
return NextResponse.json(
{ message: "회원가입 중 서버 오류가 발생했습니다." },
{ status: 500 }
);
}
}
Loading