Skip to content

Commit

Permalink
[style] prettier정렬
Browse files Browse the repository at this point in the history
  • Loading branch information
OH-GITAEK committed May 27, 2024
1 parent 2113cb1 commit 2e7e90d
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 21 deletions.
22 changes: 11 additions & 11 deletions api/middlewares/authentication.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
const jwt = require('jsonwebtoken');
const SECRET_KEY = 'piro'; // 나중에 환경 파일
const jwt = require("jsonwebtoken");
const SECRET_KEY = "piro"; // 나중에 환경 파일

// JWT 검증 미들웨어
const authenticateToken = (req, res, next) => {
const authHeader = req.headers['authorization'];
const token = authHeader && authHeader.split(' ')[1];
const authHeader = req.headers["authorization"];
const token = authHeader && authHeader.split(" ")[1];

if (token == null) return res.sendStatus(401); // 토큰 없음
if (token == null) return res.sendStatus(401); // 토큰 없음

jwt.verify(token, SECRET_KEY, (err, user) => {
if (err) return res.sendStatus(403); // 토큰 무효
req.user = user; // 이 이후에는 req.user가 user 임
next();
});
jwt.verify(token, SECRET_KEY, (err, user) => {
if (err) return res.sendStatus(403); // 토큰 무효
req.user = user; // 이 이후에는 req.user가 user 임
next();
});
};

module.exports = authenticateToken;
module.exports = authenticateToken;
22 changes: 12 additions & 10 deletions api/routers/userRouters.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,22 @@
const express = require('express');
const express = require("express");
const router = express.Router();
const userController = require('../controllers/userController');
const authenticateToken = require('../middlewares/authentication');
const userController = require("../controllers/userController");
const authenticateToken = require("../middlewares/authentication");

// 회원 가입
router.post('/signup', userController.createUser);
// 회원 가입
router.post("/signup", userController.createUser);
// 로그인
router.post('/login', userController.login);
router.post("/login", userController.login);
// 모든 유저 정보
router.get('/users', authenticateToken, userController.getAllUsers);
router.get("/users", authenticateToken, userController.getAllUsers);
// 특정 유저
router.get('/users/:id', authenticateToken, userController.getUserById);
router.get("/users/:id", authenticateToken, userController.getUserById);
// 유저 수정
router.put('/users/:id', authenticateToken, userController.updateUser);
router.put("/users/:id", authenticateToken, userController.updateUser);
// 유저 삭제
router.delete('/users/:id', authenticateToken, userController.deleteUser);
router.delete("/users/:id", authenticateToken, userController.deleteUser);

// router.post("/signup/admin", userController.createInitAdmin);

module.exports = router;

Expand Down

0 comments on commit 2e7e90d

Please sign in to comment.