I’m trying to update the value of a cookie that is set so that a function I have will send the user to a login place. Basically a logout function. I can’t figure out why the value of my cookie value isn’t overwriting.
What I’m seeing is that a second cookie with the same name is being created in Chrome, and the cookie is not changing in FireFox.
totally confused… (image from Chrome dev tools at the bottom of the page)
package controller
import (
"fmt"
"html/template"
"net/http"
"github.com/nasquam/taskmaster/model"
)
type userLogOut struct {
userLogOutTemplate *template.Template
}
func (h userLogOut) registerRoutes() {
http.HandleFunc("/logout", h.handleUserLogOut)
http.HandleFunc("/logout/", h.handleUserLogOut)
}
func (h userLogOut) handleUserLogOut(w http.ResponseWriter, r *http.Request) {
fmt.Println("In userLogOut handleUserLogOut")
model.DeleteAuthTokenFromCookie(w)
model.CheckCookies(r)
//http.Redirect(w, r, "/login/", 301)
}
func DeleteAuthTokenFromCookie(w http.ResponseWriter) {
fmt.Println("In DeleteAuthTokenFromCookie Function")
tokenCookie := http.Cookie{Name: "authValue", Value: "deleted"}
http.SetCookie(w, &tokenCookie)
}
func CheckCookies(r *http.Request) {
EmailCookie, _ := r.Cookie("emailValue")
TokenCookie, _ := r.Cookie("authValue")
fmt.Print("Email value from CheckCookies is: ")
fmt.Println(EmailCookie)
fmt.Print("Token value from CheckCookies is: ")
fmt.Println(TokenCookie)
}