Answer the question
In order to leave comments, you need to log in
Why is the session not available in the middleware?
Why is the session visible in all files, but in the middleware net///???
AUTHMIDDLEWARE:
const jwt = require('jsonwebtoken');
module.exports = function (req, res, next) {
if (req.method === "OPTIONS") {
next()
}
try {
const token = req.headers.authorization.split(' ')[1] ;// Bearer asfasnfkajsfnjk
const email = req.session.email/////////UNDERFIND !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
console.log('ОБЪЕКТ EMAIL:', email )
if (!token) {
return res.status(401).json({message: "Не авторизован"})
}
const decoded = jwt.verify(token, process.env.SECRET_KEY)
req.user = decoded
next()
} catch (e) {
res.status(401).json({message: "Не авторизован"})
}
};
const Router = require ('express');
const { check } = require('express-validator');
const userController = require('../Controllers/userController');
const validation = require('../MiddleWare/validation');
const authMiddleware = require('../MiddleWare/authMiddleware');
const router = new Router;
router.post('/registration',
validation.registration,
userController.registration)
router.post('/login',validation.login, userController.login)
router.get('/check', authMiddleware, userController.check)/// Подключаем сюда!!!!!!!
router.get('/activate/:link', userController.activate)
router.get('/session', (req, res)=>{
console.log('груша', req.session.email) /////А вот тут сессию видно
console.log()
res.send('EPIC Seesion...');
})
module.exports = router;
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question