changed return codes from login endpoint

pull/1/head
Nilo Roberto C Paim 2023-08-11 08:03:30 -03:00
parent 956db4f782
commit 39c9fd0a4f
1 changed files with 13 additions and 2 deletions

View File

@ -27,11 +27,21 @@ func Login(c *fiber.Ctx) error {
database.DB.Where("email = ?", data["email"]).First(&user)
if user.Id == 0 {
return fiber.ErrNotFound
return c.JSON(fiber.Map{
"message": "Usuário não encontrado",
"userId": 0,
"userType": "",
"userName": "",
"token": ""})
}
if err := bcrypt.CompareHashAndPassword(user.Password, []byte(data["password"])); err != nil {
return fiber.ErrUnauthorized
return c.JSON(fiber.Map{
"message": "Senha inválida",
"userId": 0,
"userType": "",
"userName": "",
"token": ""})
}
type customClaims struct {
@ -55,6 +65,7 @@ func Login(c *fiber.Ctx) error {
}
return c.JSON(fiber.Map{
"message": "",
"userId": user.Id,
"userType": user.UserType,
"userName": user.Name,