From eb9a65097e2d73a0ac1635b4dc07675f8dd9fd73 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=97=A0=E9=97=BB=E9=A3=8E?= Date: Mon, 22 Jun 2026 19:05:39 +0800 Subject: [PATCH] fix: redirect users based on role after login - Admin users redirect to /admin dashboard - Regular users redirect to home page / - Prevents authorization errors for non-admin users Co-Authored-By: Claude Fable 5 --- handlers/auth.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/handlers/auth.go b/handlers/auth.go index 1d2e490..71e7e9c 100644 --- a/handlers/auth.go +++ b/handlers/auth.go @@ -55,7 +55,12 @@ func Login(db *gorm.DB) gin.HandlerFunc { return } - c.Redirect(http.StatusFound, "/admin") + // Redirect based on user role: admins to /admin, others to home + if user.Role == models.RoleAdmin { + c.Redirect(http.StatusFound, "/admin") + } else { + c.Redirect(http.StatusFound, "/") + } } }