demo-apps / go-gin-app

MIT License
461 stars 216 forks source link

after logged-in the menu didn't change #24

Open h1deOnBush opened 4 years ago

h1deOnBush commented 4 years ago

After I log in, the options in the menu bar are still register and login

m1ckswagger commented 4 years ago

You need to update the render() function in main.go in order to pass the variable to the templates.

func render(c *gin.Context, data gin.H, templateName string) {
    loggedInInterface, _ := c.Get("is_logged_in")
    data["is_logged_in"] = loggedInInterface.(bool)

    switch c.Request.Header.Get("Accept") {
    case "application/json":
    c.JSON(http.StatusOK, data["payload"])
    case "application/xml":
    c.XML(http.StatusOK, data["payload"])
    default:
    c.HTML(http.StatusOK, templateName, data)
    }
}