From 948f5179a2e7f861eb788eb6426af361f49e7035 Mon Sep 17 00:00:00 2001 From: Adam French Date: Tue, 9 Dec 2025 22:39:05 +0000 Subject: [PATCH] bugfixing refresh token --- backend/handlers/handle_auth.go | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/backend/handlers/handle_auth.go b/backend/handlers/handle_auth.go index 5e14fed..10ae5da 100644 --- a/backend/handlers/handle_auth.go +++ b/backend/handlers/handle_auth.go @@ -1,6 +1,7 @@ package handlers import ( + "fmt" "net/http" "adam-french.co.uk/backend/models" @@ -59,15 +60,17 @@ func (store *Store) CheckToken(ctx *gin.Context) { func (store *Store) RefreshToken(ctx *gin.Context) { refreshToken, err := ctx.Cookie("refresh_token") if err != nil { - ctx.JSON(http.StatusUnauthorized, err.Error()) + ctx.JSON(http.StatusUnauthorized, err.Error()) return } claims, err := store.Auth.VerifyJWT(refreshToken) if err != nil { - ctx.JSON(http.StatusUnauthorized, err.Error()) + ctx.JSON(http.StatusUnauthorized, err.Error()) } + fmt.Printf("claims: %v\n", claims) + userID, ok := (*claims)["id"].(uint) if !ok { ctx.JSON(http.StatusInternalServerError, gin.H{"error": "invalid token claims"}) @@ -110,7 +113,7 @@ func (store *Store) RefreshToken(ctx *gin.Context) { func (store *Store) Login(ctx *gin.Context) { var input UserCredentials if err := ctx.ShouldBindBodyWithJSON(&input); err != nil { - ctx.JSON(http.StatusBadRequest, err.Error()) + ctx.JSON(http.StatusBadRequest, err.Error()) return } @@ -121,13 +124,13 @@ func (store *Store) Login(ctx *gin.Context) { } if err := bcrypt.CompareHashAndPassword(user.Password, []byte(input.Password)); err != nil { - ctx.JSON(http.StatusUnauthorized, err.Error()) + ctx.JSON(http.StatusUnauthorized, err.Error()) return } tokens, err := store.Auth.GenerateJWT(&user) if err != nil { - ctx.JSON(http.StatusInternalServerError, err.Error()) + ctx.JSON(http.StatusInternalServerError, err.Error()) return }