Skip to content

Instantly share code, notes, and snippets.

@as27
Last active March 15, 2017 16:37
Show Gist options
  • Save as27/f2a2ed7b6b95b7a10f788402d34d2cd6 to your computer and use it in GitHub Desktop.
Save as27/f2a2ed7b6b95b7a10f788402d34d2cd6 to your computer and use it in GitHub Desktop.
Buffalo Auth Tutorial: secure routes
// Create the secure group
secure := app.Group("/secure")
// Add the middleware CheckAuth to the group
secure.Use(CheckAuth)
// Create a simple secure handler, which renders a html file
secure.GET("/",
func(c buffalo.Context) error {
return c.Render(200, r.HTML("secure/index.html"))
})
// Create a logout action, where the userID inside the session is deleted
secure.DELETE("/logout",
func(c buffalo.Context) error {
session := c.Session()
session.Delete("userID")
session.Save()
return c.Redirect(301, "/login")
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment