고병후

Make logout

const express = require("express");
var auth = function (req, res, next) {
// Session Check
// 어드민 여부 체크 필요
console.log(req.session.name);
if (req.session.name != null && req.session.name != undefined)
next();
else{
console.log("미가입자 접근")
res.sendStatus(401);
}
};
module.exports = auth;
\ No newline at end of file
const express = require("express");
const bodyParser = require("body-parser");
const router = express.Router();
router.get('/',(req,res)=>{
if (req.session.name != null && req.session.name != undefined){
console.log("req.session.name");
res.sendStatus(200);
}
else{
console.log("미가입자 접근");
res.sendStatus(401);
}
});
module.exports = router;
\ No newline at end of file
const express = require("express");
const bodyParser = require("body-parser");
const router = express.Router();
const {User}=require('../models');
router.get('/',(req,res)=>{
});
//로그아웃
router.post('/',(req,res)=>{
if(result.dataValues.pw == req.body.Password){
req.session.id = null;
req.session.name = null;
req.session.personality = null;
req.session.status = null;
req.session.isAuthorized = null;
console.log("Logout");
res.sendStatus(200);
}
})
module.exports = router;
\ No newline at end of file
const express = require("express");
const bodyParser = require("body-parser");
const router = express.Router();
const auth = require("../obj/authorize");
const {User}=require('../models');
router.get('/',(req,res)=>{
router.get('/',auth,(req,res)=>{
//메인페이지
//테스트 코드
......
......@@ -14,6 +14,8 @@ const indexRouter = require('./routes/index.js');
const loginRouter = require('./routes/login.js');
const registerRouter = require('./routes/register.js');
const mainRouter = require('./routes/main.js');
const logoutRouter = require('./routes/logout.js');
const authRouter = require('./routes/auth.js');
const app = express();
app.set('port', process.env.PORT || 3001);
......@@ -49,6 +51,9 @@ app.use(session({
app.use('/api/register',registerRouter); // 회원가입 페이지
app.use('/api/login',loginRouter); //로그인 페이지
app.use('/api/main',mainRouter);//메인페이지
app.use('/api/auth',authRouter);//가입여부 확인
app.use('/api/logout',logoutRouter);//로그아웃
//에러처리 미들웨어
......