Logged-in users don’t see login/signup pages
This commit is contained in:
@@ -103,3 +103,18 @@ func RequireAuth() gin.HandlerFunc {
|
|||||||
c.Next()
|
c.Next()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Redirects authenticated users away from public auth pages.
|
||||||
|
func PublicOnly() gin.HandlerFunc {
|
||||||
|
return func(c *gin.Context) {
|
||||||
|
app := c.MustGet("app").(*bootstrap.App)
|
||||||
|
sm := app.SessionManager
|
||||||
|
|
||||||
|
if sm.Exists(c.Request.Context(), sessionkeys.UserID) {
|
||||||
|
c.Redirect(http.StatusSeeOther, "/")
|
||||||
|
c.Abort()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
c.Next()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -11,10 +11,13 @@ func RegisterAccountRoutes(app *bootstrap.App) {
|
|||||||
r := app.Router
|
r := app.Router
|
||||||
|
|
||||||
acc := r.Group("/account")
|
acc := r.Group("/account")
|
||||||
acc.GET("/login", accountHandlers.LoginGet)
|
acc.Use(middleware.PublicOnly())
|
||||||
acc.POST("/login", accountHandlers.LoginPost)
|
{
|
||||||
acc.GET("/signup", accountHandlers.SignupGet)
|
acc.GET("/login", accountHandlers.LoginGet)
|
||||||
acc.POST("/signup", accountHandlers.SignupPost)
|
acc.POST("/login", accountHandlers.LoginPost)
|
||||||
|
acc.GET("/signup", accountHandlers.SignupGet)
|
||||||
|
acc.POST("/signup", accountHandlers.SignupPost)
|
||||||
|
}
|
||||||
|
|
||||||
// Protected logout
|
// Protected logout
|
||||||
accAuth := r.Group("/account")
|
accAuth := r.Group("/account")
|
||||||
|
|||||||
Reference in New Issue
Block a user