Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/22.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 用于服务器端身份验证检查的Angularjs、Expressjs和passportjs_Javascript_Angularjs_Node.js_Express_Passport.js - Fatal编程技术网

Javascript 用于服务器端身份验证检查的Angularjs、Expressjs和passportjs

Javascript 用于服务器端身份验证检查的Angularjs、Expressjs和passportjs,javascript,angularjs,node.js,express,passport.js,Javascript,Angularjs,Node.js,Express,Passport.js,我有一个Node.js应用程序,我在其中使用了Yeoman脚手架进行Angular。我还在服务器端使用ExpressJS 因此,我的应用程序结构基本上是: app -->views --> more files server.js 结构比这更重,但这是为了保持简单 基本上,我在服务器端使用PassportJS进行身份验证。目前正在通过AngularJS路由参数执行路由 我现在遇到了一个问题,因为我需要使用中间件方法进行身份验证: function ensureAut

我有一个Node.js应用程序,我在其中使用了Yeoman脚手架进行Angular。我还在服务器端使用ExpressJS

因此,我的应用程序结构基本上是:

app
  -->views
      --> more files
server.js
结构比这更重,但这是为了保持简单

基本上,我在服务器端使用PassportJS进行身份验证。目前正在通过AngularJS路由参数执行路由

我现在遇到了一个问题,因为我需要使用中间件方法进行身份验证:

function ensureAuthenticated(req, res, next) {
    console.log('authenticate=' + req.isAuthenticated());
    if (req.isAuthenticated()) { 
        return next(); 
    }
    res.redirect('/')
}
我已在服务器端创建了一个
应用程序。get
可检查用户是否试图在不登录的情况下访问管理页面:

app.get('/admin', ensureAuthenticated,
    function(req, res){
        console.log('get admin' + req.params);
        res.sendfile(__dirname + '/app/views/admin/users.html');
    });  
但它从来都不涉及方法。我做错了什么


任何建议都很好。

它不起作用的原因是,在客户端配置路由时,angularjs locationprovider未设置为HTMLModel5。添加了以下行:

if (!req.isAuthenticated()) {
            return res.send(401, 'User is not authorized');
        }
        next();
$locationProvider.html5Mode(true);

这基本上会从url中删除“#”。

Hi,如果我只放/admin,则身份验证有效,但我的url是localhost:8888/#/admin。如果我在express中键入url作为shownlocalhost:8888/#/admin是angular realm,那么它永远不会点击路由,所以你应该更改你的逻辑我认为ie将你的视图放在管理路径中我现在还有一个问题,那就是当我路由到管理页面时,我在浏览器上按refresh,它尝试呈现页面,但它声明没有默认引擎明确规定。我只是使用html页面?总之,管理管理端服务器端更容易/更安全,而不是使用angularjs,这很难