Logged-in users don’t see login/signup pages

This commit is contained in:
2025-10-28 22:26:15 +00:00
parent aec8022439
commit f1e16fbc52
2 changed files with 22 additions and 4 deletions

View File

@@ -103,3 +103,18 @@ func RequireAuth() gin.HandlerFunc {
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()
}
}