From d82d4c754eef889b9d7ac2a428d1e246a593e5b1 Mon Sep 17 00:00:00 2001 From: vinchent Date: Tue, 13 Aug 2024 14:12:40 +0200 Subject: [PATCH] Fix some errors --- cmd/api/handlers-api.go | 3 +++ cmd/api/helpers.go | 1 + internal/models/models.go | 3 ++- 3 files changed, 6 insertions(+), 1 deletion(-) diff --git a/cmd/api/handlers-api.go b/cmd/api/handlers-api.go index 4a6c08e..93a1b4e 100644 --- a/cmd/api/handlers-api.go +++ b/cmd/api/handlers-api.go @@ -239,6 +239,7 @@ func (app *application) CreateAuthToken(w http.ResponseWriter, r *http.Request) err := app.readJSON(w, r, &userInput) if err != nil { + app.errorLog.Println(err) app.badRequest(w, r, err) return } @@ -246,6 +247,7 @@ func (app *application) CreateAuthToken(w http.ResponseWriter, r *http.Request) // get the user from the db by email, send error if invalid email user, err := app.DB.GetUserByEmail(userInput.Email) if err != nil { + app.errorLog.Println(err) app.invalidCredentials(w) return } @@ -253,6 +255,7 @@ func (app *application) CreateAuthToken(w http.ResponseWriter, r *http.Request) // validate the password, send error if invalid password validPassword, err := app.passwordMatches(user.Password, userInput.Password) if err != nil { + app.errorLog.Println(err) app.invalidCredentials(w) return } diff --git a/cmd/api/helpers.go b/cmd/api/helpers.go index 44f17ea..5dc58a2 100644 --- a/cmd/api/helpers.go +++ b/cmd/api/helpers.go @@ -88,6 +88,7 @@ func (app *application) invalidCredentials(w http.ResponseWriter) error { } func (app *application) passwordMatches(hash, password string) (bool, error) { + app.errorLog.Println(hash, password) err := bcrypt.CompareHashAndPassword([]byte(hash), []byte(password)) if err != nil { switch { diff --git a/internal/models/models.go b/internal/models/models.go index 942a023..8d962e6 100644 --- a/internal/models/models.go +++ b/internal/models/models.go @@ -244,11 +244,12 @@ func (m *DBModel) GetUserByEmail(email string) (User, error) { &u.FirstName, &u.LastName, &u.Email, + &u.Password, &u.CreatedAt, &u.UpdatedAt, ) if err != nil { - return User{}, err + return u, err } return u, nil