Skip to content

Commit

Permalink
Merge branch 'main' into front-back
Browse files Browse the repository at this point in the history
  • Loading branch information
IsthisLee authored Dec 10, 2021
2 parents 69d1801 + 5ff79ac commit 2b89114
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
2 changes: 1 addition & 1 deletion routers/circles.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ router
}
})
.delete(async (req, res) => {
const { circles_id } = req.body;
const { circles_id } = req.params;

try {
const successCount = await circles.updateOne(
Expand Down
11 changes: 9 additions & 2 deletions routers/user.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ const express = require("express");
const router = express.Router();
const User = require("../models/users");
const jwt = require("jsonwebtoken");
const crypto = require("crypto");

const salt = crypto.randomBytes(128).toString("base64");

router.post("/register", async (req, res, next) => {
console.log(req.body);
Expand Down Expand Up @@ -49,9 +52,11 @@ router.post("/register", async (req, res, next) => {
return;
}

const encodedPW = crypto.createHash('sha512').update(pw1 + salt).digest('hex');

const user = new User({
userId: userId,
pw: pw1,
pw: encodedPW,
nickname: nickname,
});
await user.save();
Expand All @@ -63,9 +68,11 @@ router.post("/register", async (req, res, next) => {
router.post("/login", async (req, res) => {
const { userId, pw } = req.body;

const encodedPW = crypto.createHash('sha512').update(pw + salt).digest('hex');

const user = await User.findOne({ userId });

if (!user || pw !== user.pw) {
if (!user || encodedPW !== user.pw) {
res.status(400).send({
errorMessage: "아이디 또는 패스워드가 잘못됐습니다.",
});
Expand Down

0 comments on commit 2b89114

Please sign in to comment.