-
Notifications
You must be signed in to change notification settings - Fork 44
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
11 changed files
with
377 additions
and
23 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { MongoClient } from "mongodb"; | ||
|
||
const url = | ||
"mongodb+srv://hs0727:hsjh1004!@cluster0.aeptwaq.mongodb.net/check-email?retryWrites=true&w=majority&appName=Cluster0"; | ||
const options: any = { useNewUrlParser: true }; | ||
|
||
let cachedClient: MongoClient | null = null; | ||
|
||
export async function connectDB(): Promise<MongoClient> { | ||
if (cachedClient) { | ||
return cachedClient; | ||
} | ||
|
||
const client = new MongoClient(url, options); | ||
await client.connect(); | ||
|
||
cachedClient = client; | ||
return client; | ||
} |
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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
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,33 @@ | ||
import type { NextApiRequest, NextApiResponse } from "next"; | ||
import { connectDB } from "db/dbConnect"; | ||
|
||
export default async function handler( | ||
req: NextApiRequest, | ||
res: NextApiResponse | ||
) { | ||
try { | ||
// 데이터베이스 연결 | ||
const client = await connectDB(); | ||
const db = client.db(); | ||
|
||
if (req.method !== "POST") { | ||
return res.status(405).json({ message: "Method not allowed" }); | ||
} | ||
|
||
const { email } = req.body; | ||
|
||
// 이메일이 이미 존재하는지 확인 | ||
const existingEmail = await db.collection("users").findOne({ email }); | ||
if (existingEmail) { | ||
return res.status(409).json({ message: "이미 사용 중인 이메일입니다." }); | ||
} | ||
|
||
// 이메일이 존재하지 않으면 새로 추가 | ||
await db.collection("users").insertOne({ email }); | ||
|
||
return res.status(200).json({ message: "사용 가능한 이메일입니다." }); | ||
} catch (error) { | ||
console.error("Error:", error); | ||
return res.status(500).json({ message: "서버 오류 발생" }); | ||
} | ||
} |
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 |
---|---|---|
@@ -1,16 +1,11 @@ | ||
import { NextApiRequest, NextApiResponse } from "next"; | ||
|
||
export default async function handler( | ||
req: NextApiRequest, | ||
res: NextApiResponse | ||
) { | ||
if (req.method === "POST") { | ||
const { email, password } = req.body; | ||
export default function handler(req: NextApiRequest, res: NextApiResponse) { | ||
const { email, password } = req.body; | ||
|
||
if (email === "test@codeit.com" && password === "sprint101") { | ||
res.status(200).json({ success: true }); | ||
} else { | ||
res.status(401).json({ success: false, message: "로그인 실패" }); | ||
} | ||
if (email === "test@codeit.com" && password === "sprint101") { | ||
res.status(200).json({ success: true }); | ||
} else { | ||
res.status(401).json({ success: false, message: "로그인 오류" }); | ||
} | ||
} |
Oops, something went wrong.