我在使用aurelia-auth插件时遇到问题。我可以从后端请求令牌并获得成功的响应 - 但是,我的应用程序似乎未经过身份验证,并且没有令牌保存到本地存储。
AUTH-config.js
var config = {
baseUrl: 'http://localhost:64794',
signupUrl: 'users',
loginUrl: 'api/values/PostPassword',
tokenName: 'id_token',
loginRedirect: '#/welcome',
authHeader: 'Authorization',
authToken: 'Bearer',
storage: 'localStorage'
}
export default config;
login.js
import {AuthService} from 'aurelia-auth';
import {inject} from 'aurelia-framework';
@inject(AuthService)
export class Login {
heading = 'Login';
email = '';
password = '';
loginError = '';
constructor(auth) {
this.auth = auth;
};
login() {
return this.auth.login(this.email, this.password)
.then(response => {
console.log("Login response: " + response);
console.log("Auth: " + this.auth.isAuthenticated());
})
.catch(error => {
this.loginError = error.response;
});
};
}
控制台输出:
Login response: eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1bmlxdWVfbmFtZSI6ImIiLCJuYmYiOjE1MDkyNzkxMzYsImV4cCI6MTUwOTI4MDMzNiwiaWF0IjoxNTA5Mjc5MTM2fQ.4QZu8pQI-K_71x_CKT9ANu1vQD7VvVUcyep51CvvCXg
login.js:27 Auth: false
任何建议都将受到赞赏。