From 0d332741956e8aaa1a8fb0916a2fa7f2cc21d0e7 Mon Sep 17 00:00:00 2001 From: Adam French Date: Tue, 9 Dec 2025 22:46:40 +0000 Subject: [PATCH] bugfixing refresh token --- backend/handlers/handle_auth.go | 6 ++++-- backend/handlers/handle_user.go | 8 +++++--- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/backend/handlers/handle_auth.go b/backend/handlers/handle_auth.go index 10ae5da..9655e64 100644 --- a/backend/handlers/handle_auth.go +++ b/backend/handlers/handle_auth.go @@ -41,11 +41,12 @@ func (store *Store) CheckToken(ctx *gin.Context) { return } - userID, ok := (*claims)["id"].(uint) + userIDF, ok := (*claims)["id"].(float64) if !ok { ctx.JSON(401, gin.H{"error": "claims does not contain id"}) return } + userID := uint(userIDF) user := models.User{Model: gorm.Model{ID: userID}} tx := store.DB.First(&user) @@ -71,11 +72,12 @@ func (store *Store) RefreshToken(ctx *gin.Context) { fmt.Printf("claims: %v\n", claims) - userID, ok := (*claims)["id"].(uint) + userIDF, ok := (*claims)["id"].(float64) if !ok { ctx.JSON(http.StatusInternalServerError, gin.H{"error": "invalid token claims"}) return } + userID := uint(userIDF) user := models.User{} tx := store.DB.First(&user, userID) diff --git a/backend/handlers/handle_user.go b/backend/handlers/handle_user.go index 337003b..e1399c2 100644 --- a/backend/handlers/handle_user.go +++ b/backend/handlers/handle_user.go @@ -90,11 +90,12 @@ func (store *Store) UpdateUser(ctx *gin.Context) { return } - userID, ok := (*claims)["id"].(uint) + userIDF, ok := (*claims)["id"].(float64) if !ok { ctx.JSON(http.StatusInternalServerError, gin.H{"error": "invalid user id in claims"}) return } + userID := uint(userIDF) var user models.User if err := store.DB.First(&user, userID).Error; err != nil { @@ -118,11 +119,12 @@ func (store *Store) DeleteUser(ctx *gin.Context) { return } - userID, ok := (*claims)["id"].(uint) + userIDF, ok := (*claims)["id"].(float64) if !ok { ctx.JSON(http.StatusInternalServerError, gin.H{"error": "invalid user id in claims"}) return } + userID := uint(userIDF) var user models.User if err := store.DB.First(&user, userID).Error; err != nil { @@ -131,5 +133,5 @@ func (store *Store) DeleteUser(ctx *gin.Context) { } store.DB.Delete(&user) - ctx.JSON(http.StatusOK, user) + ctx.JSON(http.StatusOK, user) }