I am using GoLang as the back end for my web app. All is working well until I try and preserve the user login using the combination of Ajax/Gorilla Sessions and a browser.
When using a rest client the session is storing as expected, but when performing the same action in browser I first got a CORS error but after fixing that by using "github.com/rs/cors" the issue now is the session is not being preserved
Any help would be appreciated
var store = sessions.NewCookieStore([]byte("something-very-secret"))
func main() {
mux := http.NewServeMux()
mux.HandleFunc("/set", SetCookie)
mux.HandleFunc("/get", ViewCookie)
handler := cors.Default().Handler(mux)
log.Fatal(http.ListenAndServe(":8081", handler))
}
func SetCookie(w http.ResponseWriter, r *http.Request) {
session, _ := store.Get(r, "kanban")
session.Values["username"] = "edred"
session.Save(r, w)
fmt.Fprintln(w, "cookie saved")
}
func ViewCookie(w http.ResponseWriter, r *http.Request) {
session, _ := store.Get(r, "kanban")
fmt.Fprintln(w, session.Values["username"])
}
Aucun commentaire:
Enregistrer un commentaire