繁体   English   中英

AngularJs重定向URL未将授权标头传递给服务器

[英]AngularJs Redirect URL not passing Authorization header to server

我正在从事AngularJs项目,对Web来说还很陌生。 我试图实现的是简单的登录。 我已经在服务器端(nodejs)以及客户端上实现了令牌基础认证。

一切似乎都很好。 除了我尝试

this。$ window.location.href

当我单击登录名以测试我的身份验证是否正常运行时,我已将$ http.get调用到授权端点,它可以正常工作。 然后,我调用nodejs(serve)为我提供给定端点上的页面,该页面需要授权令牌标头。 但是它没有被发送。

  public loginClick = () => {
        this.authService.login(this.user).then(msg => {
            console.log("success");
            this.$http.get(Config.apiEndpoint().url + '/memberinfo').then(result => { 

                console.log(result.data); //<== this works
                var landingUrl = "http://" + this.$window.location.host + "/dashboard/";
                this.$window.location.href = landingUrl; //<== this does not works
            });

        }, errMsg => {
            console.log("failes");
        });

    }

nodejs代码

app.get('/', moduleRoutes.root);
app.get('/dashboard/', moduleRoutes.root);

export function root(req: express.Request, res: express.Response) {
    if (authorization.isAuthorized(req, res)) {
        res.sendfile('./public/views/index.html');
    } else {
        res.sendfile('./public/views/login.html');
    }
};

您应该这样使用$ location:

 public loginClick = () => {
        this.authService.login(this.user).then(msg => {
            console.log("success");
            this.$http.get(Config.apiEndpoint().url + '/memberinfo').then(result => { 

                console.log(result.data);
                $location.path('/dashboard');
            });

        }, errMsg => {
            console.log("failes");
        });

    }

谢谢与欢呼

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM