From 5ea3dc6eae3ddf793153245a909cb2fea93023e1 Mon Sep 17 00:00:00 2001 From: Adam French Date: Wed, 10 Dec 2025 04:55:59 +0000 Subject: [PATCH] bugfix --- backend/handlers/handle_post.go | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/backend/handlers/handle_post.go b/backend/handlers/handle_post.go index c817550..88dc89f 100644 --- a/backend/handlers/handle_post.go +++ b/backend/handlers/handle_post.go @@ -52,11 +52,12 @@ func (store *Store) CreatePost(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) // Create post post := models.Post{Title: input.Title, Content: input.Content, AuthorID: userID} @@ -89,11 +90,12 @@ func (store *Store) UpdatePost(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) if !(userID == post.AuthorID) { ctx.JSON(http.StatusUnauthorized, gin.H{"error": "user and post author id missmatch"}) @@ -136,11 +138,12 @@ func (store *Store) DeletePost(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) if !(userID == post.AuthorID) { ctx.JSON(http.StatusUnauthorized, gin.H{"error": "user and post author id missmatch"})