0

So, I have a server.js with the function

function isLogged(req) {
    var x = false;
     if(req.session.logged === 'Yes'){
       x = true;
     }
     else{
    return false;
    }
}

I want to call this function with the javascript for another page. For example on the welcome.js page.

liorsolomon
  • 1,785
  • 14
  • 24
MoStack
  • 29
  • 2
  • 3

1 Answers1

0

i suppose you are using node.js ,To check check if user is logged in or not use this funtion a a middleware in all your application routes.

app.get('/somelink',isLogged,function(){
    if(user is logged in){
        'serve the requested page'
    }else{
        'redirect to login page'
    }
});
Ashish Kumar
  • 212
  • 1
  • 7