diff --git a/backend/internal/domain/constants.go b/backend/internal/domain/constants.go index 27c543dd..7859e596 100644 --- a/backend/internal/domain/constants.go +++ b/backend/internal/domain/constants.go @@ -13,7 +13,8 @@ const ( // Role constants const ( RoleAdmin = "admin" - RoleUser = "user" + RoleUser = "user" + RoleUserAdmin = "useradmin" ) // Platform constants diff --git a/backend/internal/server/middleware/admin_only.go b/backend/internal/server/middleware/admin_only.go index 2cd697a3..ff34da64 100644 --- a/backend/internal/server/middleware/admin_only.go +++ b/backend/internal/server/middleware/admin_only.go @@ -16,7 +16,7 @@ func AdminOnly() gin.HandlerFunc { return } - // 检查是否为管理员 + // 检查是否为超级管理员(admin) if role != service.RoleAdmin { AbortWithError(c, 403, "FORBIDDEN", "Admin access required") return diff --git a/backend/internal/service/domain_constants.go b/backend/internal/service/domain_constants.go index 17c40ba1..46db22c2 100644 --- a/backend/internal/service/domain_constants.go +++ b/backend/internal/service/domain_constants.go @@ -14,8 +14,9 @@ const ( // Role constants const ( - RoleAdmin = domain.RoleAdmin - RoleUser = domain.RoleUser + RoleAdmin = domain.RoleAdmin + RoleUser = domain.RoleUser + RoleUserAdmin = domain.RoleUserAdmin ) // Affiliate rebate settings diff --git a/backend/internal/service/user.go b/backend/internal/service/user.go index f9833611..90725f02 100644 --- a/backend/internal/service/user.go +++ b/backend/internal/service/user.go @@ -63,7 +63,7 @@ type User struct { } func (u *User) IsAdmin() bool { - return u.Role == RoleAdmin + return u.Role == RoleAdmin || u.Role == RoleUserAdmin } func (u *User) IsActive() bool { diff --git a/frontend/src/router/index.ts b/frontend/src/router/index.ts index 656421cc..49bab903 100644 --- a/frontend/src/router/index.ts +++ b/frontend/src/router/index.ts @@ -765,8 +765,8 @@ router.beforeEach((to, _from, next) => { return } - // Check admin requirement - if (requiresAdmin && !authStore.isAdmin) { + // Check admin requirement (requires admin role, not useradmin) + if (requiresAdmin && !authStore.isSuperAdmin) { // User is authenticated but not admin, redirect to user dashboard next('/dashboard') return diff --git a/frontend/src/stores/auth.ts b/frontend/src/stores/auth.ts index 4b712692..e0a1d758 100644 --- a/frontend/src/stores/auth.ts +++ b/frontend/src/stores/auth.ts @@ -87,6 +87,10 @@ export const useAuthStore = defineStore('auth', () => { }) const isAdmin = computed(() => { + return user.value?.role === 'admin' || user.value?.role === 'useradmin' + }) + + const isSuperAdmin = computed(() => { return user.value?.role === 'admin' }) @@ -476,6 +480,7 @@ export const useAuthStore = defineStore('auth', () => { // Computed isAuthenticated, isAdmin, + isSuperAdmin, isSimpleMode, hasPendingAuthSession,