diff options
author | Gabriel Arakaki Giovanini <mail@gabrielgio.me> | 2023-08-25 22:35:47 +0200 |
---|---|---|
committer | Gabriel Arakaki Giovanini <mail@gabrielgio.me> | 2023-08-25 22:35:47 +0200 |
commit | 869f50db2fbc24826762fb61d35e5f8de79296c1 (patch) | |
tree | 10bd08d7d4b34b61f74e5758e9157c2e10e069fc /pkg/service | |
parent | c9e5d242cbba5e3b9d3ddc4465a9a1367e44cd16 (diff) | |
download | lens-869f50db2fbc24826762fb61d35e5f8de79296c1.tar.gz lens-869f50db2fbc24826762fb61d35e5f8de79296c1.tar.bz2 lens-869f50db2fbc24826762fb61d35e5f8de79296c1.zip |
feat: Handle login error
Diffstat (limited to 'pkg/service')
-rw-r--r-- | pkg/service/auth.go | 12 |
1 files changed, 9 insertions, 3 deletions
diff --git a/pkg/service/auth.go b/pkg/service/auth.go index 30e574a..2fc06e3 100644 --- a/pkg/service/auth.go +++ b/pkg/service/auth.go @@ -21,6 +21,8 @@ type AuthController struct { key []byte } +var InvalidLogin = errors.New("Invalid login") + func NewAuthController( authRepository repository.AuthRepository, userRepository repository.UserRepository, @@ -35,17 +37,21 @@ func NewAuthController( func (c *AuthController) Login(ctx context.Context, username, password []byte) ([]byte, error) { id, err := c.authRepository.GetIDByUsername(ctx, string(username)) - if err != nil { + if errors.Is(err, repository.ErrRecordNotFound) { + return nil, InvalidLogin + } else if err != nil { return nil, err } hashedPassword, err := c.authRepository.GetPassword(ctx, id) - if err != nil { + if errors.Is(err, repository.ErrRecordNotFound) { + return nil, InvalidLogin + } else if err != nil { return nil, err } if err := bcrypt.CompareHashAndPassword(hashedPassword, password); err != nil { - return nil, err + return nil, InvalidLogin } token := &Token{ |