From 09aa311d520c0cf36c141f37186473a0796832c0 Mon Sep 17 00:00:00 2001 From: Hayden Hargreaves Date: Sun, 27 Jul 2025 14:20:42 -0700 Subject: [PATCH] (FIX): This got missed... This is part of the merge that fixed the issues with the nil derefs --- internal/app/handlers/engagement_handler.go | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/internal/app/handlers/engagement_handler.go b/internal/app/handlers/engagement_handler.go index 1c1f00b..9e35182 100644 --- a/internal/app/handlers/engagement_handler.go +++ b/internal/app/handlers/engagement_handler.go @@ -113,7 +113,15 @@ func EngagementFavoriteRecipe(ctx *gin.Context) { func EngagementMakeRecipe(ctx *gin.Context) { deps := ctx.MustGet("deps").(*domain.InjectedDependencies) - if !domain.IsLoggedIn(ctx) { + // Ensure user is logged in with a valid account + user := deps.UserService.GetAuthenicatedUser(ctx) + if user == nil { + // Log (stale) user out + domain.SetCookie(ctx, "jwt_token", "", -1) + domain.SetCookie(ctx, "search-filters", "", -1) + } + + if !domain.IsLoggedIn(ctx) || user == nil { ctx.Header("HX-Redirect", domain.WEB_LOGIN) ctx.Status(http.StatusOK) return @@ -121,9 +129,8 @@ func EngagementMakeRecipe(ctx *gin.Context) { id := ctx.Param("id") recipeId, _ := strconv.Atoi(id) - userId := ctx.MustGet("userId").(int) - if _, err := deps.EngagementService.UserMakeRecipe(userId, recipeId); err != nil { + if _, err := deps.EngagementService.UserMakeRecipe(user.Id, recipeId); err != nil { ctx.JSON(http.StatusInternalServerError, gin.H{ "status": http.StatusInternalServerError, "message": err.Error(), -- 2.47.2