1 year ago

#355237

test-img

Ayman Elmalah

Go gin session after redirecting

Session is working fine in the same handler, but when redirecting from route to other one, session is not working

also i used session in routing class like this

store := cookie.NewStore([]byte("secret"))
router.Use(sessions.Sessions("sessions", store))

Here is the controller code

func (controller *TestController) Register(c *gin.Context) {
    var session = sessions.Default(c)

    session.AddFlash(models.ErrorMsg{Field: "name", Message: "invalid input"}, "errors")
    session.Save()

    c.Redirect(http.StatusMovedPermanently, "/register")
    return
}

func (controller *TestController) HandleRegister(c *gin.Context) {
    var session = sessions.Default(c)

    errors := session.Flashes("errors")

    c.JSON(200, gin.H{
        "errors": errors,
    })
}

go

go-gin

0 Answers

Your Answer

Accepted video resources