Last active
March 15, 2017 16:37
-
-
Save as27/f2a2ed7b6b95b7a10f788402d34d2cd6 to your computer and use it in GitHub Desktop.
Buffalo Auth Tutorial: secure routes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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