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(),