diff --git a/internal/app/handlers/auth_handler.go b/internal/app/handlers/auth_handler.go index e21d3cf..4fa0a66 100644 --- a/internal/app/handlers/auth_handler.go +++ b/internal/app/handlers/auth_handler.go @@ -36,18 +36,7 @@ func GoogleCallback(ctx *gin.Context) { if jwt, dbUser, googleUserInfo, err := deps.AuthService.GoogleAuthSuccess(state, code); err != nil { ctx.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()}) } else { - // TODO: Update these values when using a real domain. Maybe an ENV? domain.SetCookie(ctx, "jwt_token", jwt, time.Hour*24*7) - // ctx.SetCookie( - // "jwt_token", - // jwt, - // int(time.Now().Add(7*24*time.Hour).Sub(time.Now()).Seconds()), - // "/", - // "", // TODO: Real live domain - // false, // TODO: True in prod - // true, - // ) - // ctx.JSON(http.StatusOK, gin.H{"jwt": jwt, "googleUserInfo": googleUserInfo, "dbUser": dbUser}) _ = dbUser _ = googleUserInfo @@ -60,11 +49,7 @@ func GoogleCallback(ctx *gin.Context) { // require authentication will require the user to sign back in before accessing them again. // This route will direct the user back to the home page. func Logout(ctx *gin.Context) { - // TODO: Use same values as the GoogleCallback function domain.SetCookie(ctx, "jwt_token", "", -1) domain.SetCookie(ctx, "search-filters", "", -1) - // ctx.SetCookie("jwt_token", "", -1, "/", "", false, true) // TODO: Update settings - // ctx.SetCookie("search-filters", "", -1, "/", "", false, true) - ctx.Redirect(http.StatusSeeOther, domain.WEB_HOME) } diff --git a/internal/app/handlers/page_handler.go b/internal/app/handlers/page_handler.go index 4227f46..5d16eb2 100755 --- a/internal/app/handlers/page_handler.go +++ b/internal/app/handlers/page_handler.go @@ -28,6 +28,14 @@ func HomePage(ctx *gin.Context) { loggedIn := domain.IsLoggedIn(ctx) + // Ensure user is logged in with a valid account + if user := deps.UserService.GetAuthenicatedUser(ctx); user == nil { + // Log (stale) user out + domain.SetCookie(ctx, "jwt_token", "", -1) + domain.SetCookie(ctx, "search-filters", "", -1) + loggedIn = false + } + var page templ.Component if loggedIn { userId := ctx.MustGet("userId").(int) @@ -214,6 +222,15 @@ func RecipePage(ctx *gin.Context) { // Get signed in user, if they exist var userId *int = nil var loggedIn = domainServer.IsLoggedIn(ctx) + + // Ensure user is logged in with a valid account + if user := deps.UserService.GetAuthenicatedUser(ctx); user == nil { + // Log (stale) user out + domain.SetCookie(ctx, "jwt_token", "", -1) + domain.SetCookie(ctx, "search-filters", "", -1) + loggedIn = false + } + if loggedIn { storeId := ctx.MustGet("userId").(int) userId = &storeId