From 334550cef9c19740239d31c19006b5df41ce1c96 Mon Sep 17 00:00:00 2001 From: Vicente Ferrari Smith Date: Sun, 10 May 2026 15:53:36 +0200 Subject: [PATCH] more logging --- cmd/party/common/tokens.go | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/cmd/party/common/tokens.go b/cmd/party/common/tokens.go index 24c7d5f..68a7acb 100644 --- a/cmd/party/common/tokens.go +++ b/cmd/party/common/tokens.go @@ -3,15 +3,19 @@ package common import ( "crypto/sha256" "errors" + "fmt" "time" "party.at/party/internal/data" ) func (app *Application) LoginUser(email, password string) (*data.Token, error) { + app.Logger.PrintInfo("login attempt", map[string]string{"email": email}) + user, err := app.Models.Users.GetByEmail(email) if err != nil { if errors.Is(err, data.ErrRecordNotFound) { + app.Logger.PrintInfo("login failed: user not found", map[string]string{"email": email}) return nil, data.ErrInvalidCredentials } return nil, err @@ -19,9 +23,15 @@ func (app *Application) LoginUser(email, password string) (*data.Token, error) { identities, err := app.Models.UserIdentities.GetByUser(user.ID) if err != nil { + if errors.Is(err, data.ErrRecordNotFound) { + app.Logger.PrintInfo("login failed: no identities", map[string]string{"email": email, "user_id": fmt.Sprint(user.ID)}) + return nil, data.ErrInvalidCredentials + } return nil, err } + app.Logger.PrintInfo("login: found identities", map[string]string{"email": email, "count": fmt.Sprint(len(identities))}) + var authenticatedIdentity *data.UserIdentity for _, identity := range identities { match, err := identity.Password.Matches(password) @@ -35,9 +45,11 @@ func (app *Application) LoginUser(email, password string) (*data.Token, error) { } if authenticatedIdentity == nil { + app.Logger.PrintInfo("login failed: wrong password", map[string]string{"email": email}) return nil, data.ErrInvalidCredentials } + app.Logger.PrintInfo("login success", map[string]string{"email": email, "user_id": fmt.Sprint(user.ID)}) return app.Models.Tokens.New(user.ID, authenticatedIdentity.ID, 24*time.Hour, data.ScopeAuthentication) }