feat(auth): migrate to better-auth admin plugin with unified Admin tab#3612
feat(auth): migrate to better-auth admin plugin with unified Admin tab#3612waleedlatif1 wants to merge 9 commits intostagingfrom
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub. |
|
You have used all Bugbot PR reviews included in your free trial for your GitHub account on this workspace. To continue using Bugbot reviews, enable Bugbot for your team in the Cursor dashboard. |
Greptile SummaryThis PR replaces the custom Key changes:
Confidence Score: 4/5
Important Files Changed
Flowchart%%{init: {'theme': 'neutral'}}%%
flowchart TD
A[User navigates to /settings/admin] --> B{useSession: role === 'admin'?}
B -- No --> C[effectiveSection = 'general'\nRenders General component]
B -- Yes --> D[effectiveSection = 'admin'\nRenders Admin component]
E[Settings Sidebar renders nav items] --> F{item.requiresAdminRole?}
F -- No --> G[Show item]
F -- Yes --> H{session?.user?.role === 'admin'?}
H -- No --> I[Hide item]
H -- Yes --> J[Show Admin tab]
D --> K[Super Admin Mode Toggle\nupdates generalSettings]
D --> L[Workflow Import\nvia useImportWorkflow]
D --> M[User Management\nuseAdminUsers / useSetUserRole / useBanUser / useUnbanUser]
M --> N[client.admin.listUsers]
M --> O[client.admin.setRole]
M --> P[client.admin.banUser / unbanUser]
N & O & P --> Q[better-auth admin plugin\ngates on role === 'admin']
|
Consolidate superuser features into a single Admin settings tab: - Super admin mode toggle (moved from General) - Workflow import (moved from Debug) - User management via better-auth admin (list, set role, ban/unban) Replace Debug tab with Admin tab gated by requiresAdminRole. Add React Query hooks for admin user operations.
Add UPDATE statement to promote is_super_user=true rows to role='admin' before dropping the is_super_user column, preventing silent demotion.
- Fix cn import path to @/lib/core/utils/cn - Use valid Badge variants (blue/gray/red/green instead of secondary/destructive) - Type setRole param as 'user' | 'admin' union
Include user.role in customSession so it's available client-side. Replace all useSuperUserStatus() calls with session.user.role === 'admin'. Delete the now-redundant /api/user/super-user endpoint.
The admin plugin already includes role on the user object. No need to manually spread it in customSession.
… practices - Remove unsafe unknown/Record casting, use better-auth typed response - Add placeholderData: keepPreviousData for paginated variable-key query - Remove nullable types where defaults are always applied
|
@greptile |
apps/sim/app/workspace/[workspaceId]/settings/components/admin/admin.tsx
Show resolved
Hide resolved
apps/sim/app/workspace/[workspaceId]/settings/components/admin/admin.tsx
Outdated
Show resolved
Hide resolved
- Fix superUserModeEnabled default to false (matches sidebar behavior) - Reset banReason when switching ban target to prevent state bleed - Guard admin section render with session role check for direct URL access
|
@greptile |
Three places defaulted to true while admin tab and sidebar used false. Align all to false so new admins see consistent behavior.
|
You have used all Bugbot PR reviews included in your free trial for your GitHub account on this workspace. To continue using Bugbot reviews, enable Bugbot for your team in the Cursor dashboard. |
Summary
isSuperUserboolean with better-auth's native admin plugin (role,banned,banReason,banExpireson user table,impersonatedByon session table)/api/user/super-userAPI route — role now available directly from session viacustomSession+ admin pluginis_super_user = truerows torole = 'admin'before dropping the columnChanges
isSuperUser→roletext field +banned/banReason/banExpirescolumns,impersonatedByon sessionadmin()server plugin andadminClient()client pluginuser.roleexposed via better-auth'scustomSession— no custom override neededuseAdminUsers,useSetUserRole,useBanUser,useUnbanUser) following project patternsrequiresAdminRolegate (checks role only, not mode toggle) so admin tab stays accessibleuseSuperUserStatushookTest plan
user.rolefield after login🤖 Generated with Claude Code