2012-08-27 3 views
0

우리는 다음과 같은 경로인증 된 노드의 경로는?

/dothis/ 
    ...//dothis routes 
/dothat 
    ...//dothat routes 
/doother 
    ...//doother routes 

및 로그인 경로와 응용 프로그램이 있습니다 경로를 닫

/login 

/ //which currently actually isn't even used, would redirect to /login 

이 가능 그렇게 실제로 단지 /과/login은 인증없이 액세스 할 수 있습니까? 또는 다른 모든 경로에 접두어를 적용해야합니까? 감사합니다

답변

0
app.get('*', function(req, res, next) { 
     // console.log(everyauth); 
     if (!req.session.auth) { 
      res.redirect('/login'); 
     } else { 
      next(); 
     } 
    }); 

app.get('/login', function(req, res){ 
    res.render('login', { 
    }); 
}); 

내가 정확히이 일을 미들웨어가

0
app.all('*', Authentication, function(req, res) { 
}); 

function Authentication(req, res, next) { 
    if (req is not user) { 
     if (req.url === '/' || req.url === '/login') 
      next() 
    } 
    else 
     next(); 
} 
0

을 작동하는 것 같다 : https://github.com/jaredhanson/connect-ensure-login

app.get('/dothat', 
    ensureLoggedIn('/login'), // redirect to /login if not logged in 
    function(req, res) { 
    // render do that; 
    }); 

이 가능한 독립형, 그러나 또한 Passport과 원활하게 통합 이후 있도록 로그인하면 사용자는 원래 요청한 URL로 리디렉션됩니다.