Skip to content

Commit

Permalink
Added more logs
Browse files Browse the repository at this point in the history
  • Loading branch information
Ju-Wiluis William Rodriguez Hernandez committed Jun 2, 2024
1 parent 9f4cbf5 commit b32ac46
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
4 changes: 2 additions & 2 deletions handlers/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,15 +82,15 @@ func ValidateHandler(w http.ResponseWriter, r *http.Request) {
}

// Validate token against Redis
username, err := redis.ValidateToken(token)
userId, err := redis.ValidateToken(token)
if err != nil {
println("Error validating token: ", err.Error())
writeJsonError(w, "Invalid token", http.StatusUnauthorized)
return
}

// Respond with username
response := map[string]string{"username": username}
response := map[string]string{"user": userId}
json.NewEncoder(w).Encode(response)
}

Expand Down
2 changes: 2 additions & 0 deletions redis/redis.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,10 @@ func GenerateToken(userId string) (string, error) {
func ValidateToken(token string) (string, error) {
val, err := GetInstance().Get(context.Background(), fmt.Sprintf("auth_token:%s", token)).Result()
if err == redis.Nil {
println("Token not Found")
return "", fmt.Errorf("token not found")
} else if err != nil {
println("Error validating with Redis: ", err.Error())
return "", err
}
return val, nil
Expand Down

0 comments on commit b32ac46

Please sign in to comment.