sessions icon indicating copy to clipboard operation
sessions copied to clipboard

Set session in POST methods, but cann't get session in GET methods

Open InterAI-CN opened this issue 6 years ago • 6 comments

When I set a session in r.POST methods, but cann't get session in r.GET methods。

InterAI-CN avatar Aug 17 '19 02:08 InterAI-CN

Are you correctly using session.Set(x, y) and session.Save() afterwards ?

alkanna avatar Aug 17 '19 07:08 alkanna

hi,I have the same problem.

func (LoginController) Set(c *gin.Context)  {
	sessionToken,_ := uuid.NewV4()
	//d6db0562-42c1-4bb2-b73e-988357fa0e6d
	session := sessions.Default(c)
	session.Set(sessionToken.String(),map[string]string{"name":"cai xu kun"})
	_ = session.Save() //important

	c.SetCookie("ginex_session",sessionToken.String(),0,"/","localhost",false,true)
}

func (LoginController) Get(c *gin.Context)  {
	sessionToken, _ := c.Cookie("ginex_session")
	fmt.Println(sessionToken)
	session := sessions.Default(c)

	value := session.Get(sessionToken)

	c.JSON(http.StatusOK,gin.H{"data":value})
}

Value is nil

jwwb681232 avatar Aug 30 '19 09:08 jwwb681232

I assumed the problem caused by input value type, this lib does handle that case well. Did you try this concept with a string value instead? @jwwb681232

vuon9 avatar Sep 08 '19 09:09 vuon9

@InterAI-CN Could you redo the POST operation vis curl, and paste HTTP Response Header in here? I think you forget session.Save()

@jwwb681232 What is c.Cookie("ginex_session")? Does you store sessionToken in there?

Zhang-Siyang avatar Nov 22 '19 09:11 Zhang-Siyang

As soon as I decomposed my complex type into strings, it worked for me

keithmattix avatar May 03 '20 05:05 keithmattix

i have the same problem, cannot get session

rendybustari avatar Apr 24 '21 06:04 rendybustari