(FIX): Working on the nil derefs, removed tx's from select queries. #37
@ -36,18 +36,7 @@ func GoogleCallback(ctx *gin.Context) {
|
|||||||
if jwt, dbUser, googleUserInfo, err := deps.AuthService.GoogleAuthSuccess(state, code); err != nil {
|
if jwt, dbUser, googleUserInfo, err := deps.AuthService.GoogleAuthSuccess(state, code); err != nil {
|
||||||
ctx.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
|
ctx.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
|
||||||
} else {
|
} else {
|
||||||
// TODO: Update these values when using a real domain. Maybe an ENV?
|
|
||||||
domain.SetCookie(ctx, "jwt_token", jwt, time.Hour*24*7)
|
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})
|
// ctx.JSON(http.StatusOK, gin.H{"jwt": jwt, "googleUserInfo": googleUserInfo, "dbUser": dbUser})
|
||||||
_ = dbUser
|
_ = dbUser
|
||||||
_ = googleUserInfo
|
_ = googleUserInfo
|
||||||
@ -60,11 +49,7 @@ func GoogleCallback(ctx *gin.Context) {
|
|||||||
// require authentication will require the user to sign back in before accessing them again.
|
// 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.
|
// This route will direct the user back to the home page.
|
||||||
func Logout(ctx *gin.Context) {
|
func Logout(ctx *gin.Context) {
|
||||||
// TODO: Use same values as the GoogleCallback function
|
|
||||||
domain.SetCookie(ctx, "jwt_token", "", -1)
|
domain.SetCookie(ctx, "jwt_token", "", -1)
|
||||||
domain.SetCookie(ctx, "search-filters", "", -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)
|
ctx.Redirect(http.StatusSeeOther, domain.WEB_HOME)
|
||||||
}
|
}
|
||||||
|
|||||||
@ -28,6 +28,14 @@ func HomePage(ctx *gin.Context) {
|
|||||||
|
|
||||||
loggedIn := domain.IsLoggedIn(ctx)
|
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
|
var page templ.Component
|
||||||
if loggedIn {
|
if loggedIn {
|
||||||
userId := ctx.MustGet("userId").(int)
|
userId := ctx.MustGet("userId").(int)
|
||||||
@ -214,6 +222,15 @@ func RecipePage(ctx *gin.Context) {
|
|||||||
// Get signed in user, if they exist
|
// Get signed in user, if they exist
|
||||||
var userId *int = nil
|
var userId *int = nil
|
||||||
var loggedIn = domainServer.IsLoggedIn(ctx)
|
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 {
|
if loggedIn {
|
||||||
storeId := ctx.MustGet("userId").(int)
|
storeId := ctx.MustGet("userId").(int)
|
||||||
userId = &storeId
|
userId = &storeId
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user