In development the login and register work but in production it is not, why is that?
in account controller (API) I have the below code to login the user. I am using this example because it is shorter to demonstrate.
[HttpPost("login")]
public async Task<IActionResult> Login(loginReqDto loginReq)
{
var user = await uow.UserRepository.Authenticate(loginReq.UserName, loginReq.Password);
ApiError apiError = new ApiError();
if(user == null)
{
apiError.ErrorCode = Unauthorized().StatusCode;
apiError.ErrorMessage = "Invalid userId or Password!";
apiError.ErrorDetails = "This is appearing when user or password does not exist!";
return Unauthorized(apiError);
}
var loginRes = new LoginResDto();
loginRes.UserName = user.Username;
loginRes.Token = CreateJWT(user);
return Ok(loginRes);
}
and in my front end (angular):
onlogin(loginForm: NgForm){
console.log(loginForm.value);
this.authServive.authUser(loginForm.value).subscribe(
(response: any) => {
console.log(response);
const user = response;
localStorage.setItem('token', user.token);
localStorage.setItem('userName', user.userName);
this.alertify.success("You have loged-in successfully!");
this.router.navigate(['/']);
});
}
In postman using development I am getting the code 200OK and generated the token. on the otherhand, in production, I get internet server error code 500.
why?