Skip to content

Commit

Permalink
refactor: error message
Browse files Browse the repository at this point in the history
Do not expose any auth details
with which hackers may guess what's behind
  • Loading branch information
crazyoptimist committed Jun 16, 2024
1 parent 95ca05e commit 8c166e3
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 10 deletions.
5 changes: 1 addition & 4 deletions internal/domain/auth/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package auth

import (
"errors"
"fmt"
"strconv"

"gin-starter/internal/domain/model"
Expand All @@ -15,8 +14,6 @@ type AuthHelper interface {
IsTokenBlacklisted(token string) (bool, error)
}

var ErrTokenBlacklisted = fmt.Errorf("Refresh token is blacklisted")

type AuthService struct {
UserRepository user.UserRepository
AuthHelper AuthHelper
Expand Down Expand Up @@ -108,7 +105,7 @@ func (s *AuthService) Refresh(logoutDto *LogoutDto) (*LoginResponse, error) {
}

if isTokenBlacklisted {
return nil, ErrTokenBlacklisted
return nil, errors.New("Invalid refresh token")
}

err = s.AuthHelper.BlacklistToken(logoutDto.RefreshToken)
Expand Down
7 changes: 1 addition & 6 deletions internal/infrastructure/controller/auth_controller.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package controller

import (
"errors"
"net/http"

"github.com/gin-gonic/gin"
Expand Down Expand Up @@ -116,11 +115,7 @@ func (a *authController) Refresh(c *gin.Context) {

refreshResponse, err := a.AuthService.Refresh(&refreshDto)
if err != nil {
if errors.Is(err, auth.ErrTokenBlacklisted) {
common.RaiseHttpError(c, http.StatusUnauthorized, err)
return
}
common.RaiseHttpError(c, http.StatusInternalServerError, err)
common.RaiseHttpError(c, http.StatusUnauthorized, err)
return
}

Expand Down

0 comments on commit 8c166e3

Please sign in to comment.