0
我正在AngularJs项目上工作,我对网络很陌生。我试图实现的是简单的登录。我已经在服务器端(nodejs)以及客户端实现了令牌库身份验证。AngularJs重定向URL没有通过授权标题到服务器
一切似乎都很好。除了当我尝试
这一点。$ 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.href – Bata
你似乎没有告诉$ http发送任何额外的头文件。你可以看看在这里设置标题的文档https://docs.angularjs.org/api/ng/service/$http/#setting-http-headers – toskv
此外,你似乎正在发回整个页面。 。你不应该使用$ http服务来做这件事。这是你可以用路由器解决的更多问题。 :) – toskv