Отправлять данные из маршрутов в html в nodejs - PullRequest
0 голосов
/ 17 сентября 2018

В настоящее время я работаю над проектом nodejs и хочу показать некоторый контент в index.ejs в зависимости от того, вошел ли пользователь в систему или нет.У меня действительно есть Google, но ничего не работает, я был бы очень признателен, если бы вы могли сказать мне, что не так.Прямо сейчас он показывает мне ошибку: isLoggedIn не определен

Вот HTML-код

const Location = require('../models/location');

module.exports = (app, passport) => {



app.get('/', isLoggedIn, (req, res) => {
    res.render('index', {
         user: req.user, isLoggedIn: req.isLogged
    });
});


app.get('/profile', isLoggedIn, (req, res) => {
    res.render('profile', {
        user: req.user
    });
});

app.get('/profile', isLoggedIn, (req, res) => {
    res.render('profile', {
      user: req.user, isLoggedIn: req.isLogged
    });
});


app.get('/getUsername',isLoggedIn,(req, res) => {
    res.json({username: req.user.email});
});

app.get('/getLocations', isLoggedIn, (req, res) => {
    Location.find({user:req.user.email},function(err, locations){
        res.json({locations:locations});
    });
});

app.post('/location', (req, res) => {
    let location = new Location()
    console.log(req.body)
    location.user = req.body.email
    console.log("LLegue al post")
    location.latitude = req.body.latitude
    location.longitude = req.body.longitude
    console.log(location.user)
    console.log(location.latitude)
    console.log(location.longitude)

    location.save((err, LocationStored)=>{
        if(err) res.status(500).send({message: `Error al salvar en la base de datos: ${err}`})
    })

    res.json({message: "Exitasion"});
});   
};

function isLoggedIn(req, res, next) {
   if (req.isAuthenticated()){
      return next();
   }
 return res.redirect('/');
}

и мой index.ejs:

<% if (isLoggedIn) { %>
//code
  <% } else{ %>  
<p>you're logged in</p>
 <% } %>
...