Fix admin login reload loop from stale localStorage tokens.
Clear client tokens on the login page, gate admin pages with shared cookie JWT checks, and clear Secure cookies reliably behind the proxy. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -4,6 +4,7 @@
|
||||
package ui
|
||||
|
||||
import (
|
||||
"bankline/internal/appresult"
|
||||
"net/http"
|
||||
"strings"
|
||||
|
||||
@@ -34,14 +35,17 @@ func Register(router *gin.Engine) {
|
||||
|
||||
admin := router.Group("/admin")
|
||||
|
||||
admin.GET("/login", func(c *gin.Context) {
|
||||
admin.GET("/login", appresult.AdminGuestOnly(), func(c *gin.Context) {
|
||||
c.HTML(http.StatusOK, "pages/login", gin.H{
|
||||
"Title": "Login",
|
||||
"Page": "login",
|
||||
})
|
||||
})
|
||||
|
||||
admin.GET("", func(c *gin.Context) {
|
||||
authed := admin.Group("")
|
||||
authed.Use(appresult.AdminPageAuth())
|
||||
|
||||
authed.GET("", func(c *gin.Context) {
|
||||
c.HTML(http.StatusOK, "pages/dashboard", gin.H{
|
||||
"Title": "Dashboard",
|
||||
"Page": "dashboard",
|
||||
@@ -49,7 +53,7 @@ func Register(router *gin.Engine) {
|
||||
})
|
||||
})
|
||||
|
||||
admin.GET("/settings", func(c *gin.Context) {
|
||||
authed.GET("/settings", func(c *gin.Context) {
|
||||
c.HTML(http.StatusOK, "pages/settings", gin.H{
|
||||
"Title": "Settings",
|
||||
"Page": "settings",
|
||||
@@ -60,7 +64,7 @@ func Register(router *gin.Engine) {
|
||||
for _, res := range resources {
|
||||
res := res
|
||||
|
||||
admin.GET("/"+res.Slug, func(c *gin.Context) {
|
||||
authed.GET("/"+res.Slug, func(c *gin.Context) {
|
||||
c.HTML(http.StatusOK, "pages/list", gin.H{
|
||||
"Title": res.Title,
|
||||
"Page": "list",
|
||||
@@ -69,7 +73,7 @@ func Register(router *gin.Engine) {
|
||||
})
|
||||
})
|
||||
|
||||
admin.GET("/"+res.Slug+"/new", func(c *gin.Context) {
|
||||
authed.GET("/"+res.Slug+"/new", func(c *gin.Context) {
|
||||
c.HTML(http.StatusOK, "pages/form", gin.H{
|
||||
"Title": "New — " + res.Title,
|
||||
"Page": "form",
|
||||
@@ -79,7 +83,7 @@ func Register(router *gin.Engine) {
|
||||
})
|
||||
})
|
||||
|
||||
admin.GET("/"+res.Slug+"/:id/edit", func(c *gin.Context) {
|
||||
authed.GET("/"+res.Slug+"/:id/edit", func(c *gin.Context) {
|
||||
c.HTML(http.StatusOK, "pages/form", gin.H{
|
||||
"Title": "Edit — " + res.Title,
|
||||
"Page": "form",
|
||||
|
||||
Reference in New Issue
Block a user