Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

103
Vistas
Use reactjs to get login info from golang session

I am making a backend using go, frontend using react.

Now I build a login page and use session to remember user login status.

I originally used postman to test the golang func, and now I want to write it in reactjs, but I found that I can't just use get, and I need to add cookie information

In the code field of postman, it is found that after sending the command, it will automatically add header: cookie data, and when using curl, adding "-v" option will also return setCookie information, but I have no idea how to get the cookie information on the client side.

Here is my golang func, can somebody give me suggestion about js cookie?

func main() {
    r := gin.Default()
    
    store := cookie.NewStore([]byte("secret"))
    r.Use(sessions.Sessions("mysession", store))
    r.GET("/setSession", setUser)
    getSession(r)
}
func setUser(c *gin.Context) {
    session := sessions.Default(c)
    session.Set("currentUser", *db)
    session.Options(sessions.Options{
        MaxAge: 50,
    })
    session.Save() 
    c.String(200, "session setup: %v", session.Get("currentUser"))
}

func getSession(r *gin.Engine) {
    r.GET("/Hey", api.Cookie(), func(c *gin.Context) {
        userInfo := getCurrentUser(c)
        if userInfo.Username == "admin" {
            c.String(http.StatusOK, "Hello "+userInfo.Username)
        } else {
            c.String(http.StatusOK, "Failed")
        }
    })

}
func getCurrentUser(c *gin.Context) (userInfo User) {
    session := sessions.Default(c)
    userInfo = session.Get("nowUser").(User)
    return
}
about 4 years ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda