Skip to content

Commit

Permalink
FIX: 로그인, 회원가입에러 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
kth2624 committed May 5, 2022
1 parent 9a5248f commit 01bb5ce
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 18 deletions.
8 changes: 1 addition & 7 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,4 @@ jobs:
username: ${{ secrets.USER }}
password: ${{ secrets.PASSWORD }}
script: |
cd Together
git reset --hard
git fetch
git pull
npm i
pm2 delete 0
pm2 start --no-daemon app.js
./deploy.sh
12 changes: 5 additions & 7 deletions controller/auth.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,16 @@ import {} from 'express-async-errors';
import * as userRepository from '../data/auth.js';
import { config } from '../config.js';

//id pw email name gender location hobby

export async function signUp(req, res) {
const { intraId, pw, email, url } = req.body;
const { intraId, password, email, url } = req.body;
const user = await userRepository.findByintraId(intraId);
if(user){ //이미 존재하는 사용자라면
return res.status(400).json({message: `${intraId} already exists`});
}
const hashed = await bcrypt.hash(pw, config.bcrypt.saltRounds);
const hashed = await bcrypt.hash(password, config.bcrypt.saltRounds);
const userId = await userRepository.createUser({
intraId,
pw: hashed,
password: hashed,
email,
url,
});
Expand All @@ -24,12 +22,12 @@ export async function signUp(req, res) {
}

export async function login(req, res) {
const { intraId, pw } = req.body;
const { intraId, password } = req.body;
const user = await userRepository.findByintraId(intraId);
if(!user){//사용자가 존재하는지 검사
return res.status(401).json({message: 'Invalid user or password'});
}
const isValidPassword = await bcrypt.compare(pw, user.pw);
const isValidPassword = await bcrypt.compare(password, user.password);
if(!isValidPassword){//비밀먼호 검증
return res.status(401).json({message: 'Invalid user or password'});
}
Expand Down
6 changes: 3 additions & 3 deletions data/auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ export async function findByintraId(intraId) {
}

export async function createUser(user) {
const {intraId, pw, email, url} = user;
const {intraId, password, email, url} = user;
return db
.execute('INSERT INTO users (intraId, pw, email, url) VALUES (?,?,?,?)',
[intraId, pw, email, url]
.execute('INSERT INTO users (intraId, password, email, url) VALUES (?,?,?,?)',
[intraId, password, email, url]
)
.then((result) => result[0].insertId);
}
2 changes: 1 addition & 1 deletion routes/auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ const validateCredential = [
.notEmpty()
.isLength({min:2})
.withMessage('intraId should be at least 2 characters'),
body('pw')
body('password')
.trim()
.isLength({min:8})
.withMessage('password should be at least 5 characters'),
Expand Down

0 comments on commit 01bb5ce

Please sign in to comment.