Commit 9fe5e544 authored by Lee Soobeom's avatar Lee Soobeom
Browse files

Merge branch 'sb6' into sb7

parents b8dcc783 3b01ee29
......@@ -35,7 +35,7 @@ export const login = asyncWrap(async (req, res) => {
maxAge: cookieConfig.maxAge, // 이 기간 내에서만 유효
path: "/", //어떠한 경로에 관해서만 쓴다. 지금은 전부에 쓴다.
httpOnly: envConfig.mode === "production", //false면 브라우저에서 쿠키를 조작, true면 조작할 수 없다.
secure: envConfig.mode === "production", //true 면 https를 통해서만 쿠키 전달, false면
secure: envConfig.mode === "production", // true면 https를 통해서만 쿠키 전달, false면 불가능
});
// 5) 사용자 반환
res.json({
......@@ -89,6 +89,7 @@ export const signup = asyncWrap(async (req, res) => {
// 3) 비밀번호 암호화는 useDb.createUser에서 처리
// 4) 새로운 사용자 만들기
const newUser = await userDb.createUser({
name,
email,
password,
});
......
import { NextFunction, Request, Response } from "express";
import isLength from "validator/lib/isLength";
import equals from "validator/lib/equals";
import { requireLogin } from "./auth.controller";
import { asyncWrap } from "../helpers";
import { postDb } from "../db";
......@@ -9,6 +10,8 @@ export const posting = asyncWrap(async (req, res) => {
console.log("body", req.body);
// 0) 로그인 했는지 확인 requireLogin
// 1) title 빈 문자열인지 확인
if (!isLength(title ?? "", { min: 1 })) {
return res.status(422).send("제목을 한 글자 이상 입력해주세요");
......@@ -29,9 +32,8 @@ export const posting = asyncWrap(async (req, res) => {
return res.status(422).send("도시를 선택해 주세요");
}
// 5) username 확인 필요 없음
// 5) username ref: cookie.token._id -> collection users, "User"-> name
// 6)
const newPosting = await postDb.createPosting({
title,
text,
......
......@@ -9,7 +9,7 @@ export const createPosting = async (posting: PostingType) => {
city: posting.city,
username: posting.username,
date: posting.date,
counts: posting.counts,
counts: 0,
});
return newPosting;
};
......@@ -4,7 +4,11 @@ import { IUser, User } from "../models";
export const createUser = async (user: IUser) => {
// 비밀번호 암호화
const hash = await bcrypt.hash(user.password, 10);
const newUser = await User.create({ email: user.email, password: hash });
const newUser = await User.create({
email: user.email,
password: hash,
name: user.name,
});
return newUser;
};
......
......@@ -27,6 +27,14 @@ const postingSchema = new Schema<PostingType>({
},
username: {
type: String,
// username: travelreport.users.findOne({id: cookie.token._id(Schema.Tpyes.ObjectId)}).name,
},
date: {
type: Date,
default: Date.now,
},
counts: {
type: Number,
},
date: {
type: Date,
......
......@@ -8,6 +8,5 @@ const router = express.Router();
router.use("/users", userRouter);
router.use("/auth", authRouter);
router.use("/posts", postRouter);
//posting함수 -> mongodb에 posts json형식으로 저장
export default router;
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment