В моем реагирующем веб-сайте я захожу, чтобы создать токен.Я вызываю мой API, а ответная реакция не определена.
[object Error]{config: Object {...}, description: "Network Error",
message: "Network Error", name: "Error", request: XMLHttpRequest {...}, response: undefined, stack: "Error: Netw..."}
Это мой код реакции.
const axios = require("axios");
const fakeAuth = {
isAuthenticated: false,
authenticate(cb: any) {
this.isAuthenticated = true;
axios.post('https://localhost:44310/api/Users/Token' )
.then((response : any) => {
console.log(response)
})
.catch((error : any) =>{
console.log(error)
})
},
signout(cb: any) {
this.isAuthenticated = false;
},
getValue() {
return this.isAuthenticated;
}
};
export default fakeAuth;
и это мой метод токена API.
private string Token()
{
var key = new SymmetricSecurityKey(Encoding.UTF8.GetBytes("qwertyuiopqwertyuiop"));
var signInCred = new SigningCredentials(key, SecurityAlgorithms.HmacSha256Signature);
var token = new JwtSecurityToken(
issuer: "localhost",
audience: "localhost",
expires: DateTime.Now.AddMinutes(1),
signingCredentials: signInCred
);
var tokenString = new JwtSecurityTokenHandler().WriteToken(token);
return tokenString;
}