(FIX): Working on the nil derefs, removed tx's from select queries. #37

Merged
azpect merged 6 commits from dev into master 2025-07-27 14:12:09 -07:00
2 changed files with 17 additions and 15 deletions
Showing only changes of commit dbf8470195 - Show all commits

View File

@ -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)
}

View File

@ -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