The moderator role system has been implemented! Here's how to make yourself a moderator:
npm run devGo to: http://localhost:3000/admin/setup
- Enter your email address (the one you signed up with)
- Select "Moderator" from the dropdown
- Click "Set Role"
- Wait 2 seconds - you'll be automatically redirected to the moderator dashboard
After setting your role, you can access: http://localhost:3000/admin/moderator
- Go to MongoDB Atlas
- Log in and navigate to your cluster
- Click "Browse Collections"
- Find the
stem-magazinedatabase - Click on the
Usercollection - Find your user document (search by your email)
- Click "Edit"
- Change
"role": "USER"to"role": "MODERATOR"or"role": "ADMIN" - Click "Update"
- Refresh your app
- Open terminal in your project
- Run:
npx prisma studio - This opens a GUI at
http://localhost:5555 - Click on
Usertable - Find your user record
- Change the
rolefield to"MODERATOR"or"ADMIN" - Click "Save 1 change"
- Refresh your app
- Can create submissions
- Can save drafts
- Can view their own dashboard
- Cannot access moderator dashboard
- All USER permissions
- Can view all submissions at
/admin/moderator - Can approve submissions (creates published posts)
- Can reject submissions (with reason)
- Cannot set roles for other users
- All MODERATOR permissions
- Can set roles for any user
- Full system access
/admin/setup page currently allows ANY authenticated user to set their own role. This is for initial setup convenience.
-
Remove the setup page after setting up your initial moderators:
del src\app\admin\setup\page.tsx
-
Or restrict the setup page by modifying
src/app/api/admin/set-role/route.tsto only allow the first user, or check for an environment variable:// Only allow if no admins exist yet const adminCount = await prisma.user.count({ where: { role: 'ADMIN' }, }); if (adminCount > 0 && !callerHasAdminRole) { return NextResponse.json( { error: 'Setup already completed' }, { status: 403 } ); }
-
Use MongoDB Atlas to manually set roles for additional moderators
/admin/*routes check for authentication (via Clerk)/admin/moderatorpage checks for MODERATOR or ADMIN role/api/admin/submissionsAPI checks for MODERATOR or ADMIN role
- User visits
/admin/moderator - Clerk middleware checks authentication
- Page component calls
/api/admin/check-role - API queries database for user's role
- If MODERATOR or ADMIN: show dashboard
- If USER: redirect to home page
- User visits
/admin/setup - Enters email and selects role
- Submits form to
/api/admin/set-role - API checks if caller is ADMIN or setting their own role
- Updates user record in database
- User can now access moderator dashboard
- Sign up with a new account or use your existing one
- Set your role to MODERATOR using the setup page
- Visit
/admin/moderator- you should see the dashboard - Create a submission as a regular user
- Approve/reject it from the moderator dashboard
- Check that approved posts appear in
/posts
- Check that you've set your role correctly
- Make sure you're signed in with the same email you used in the setup page
- Try signing out and back in
- Check MongoDB to verify the
rolefield is set
- Sign out and sign back in
- Restart the dev server
- Clear your browser cache
- Check that Prisma generated correctly:
npx prisma generate
- Make sure the dev server is running
- Check that the file exists:
src/app/admin/setup/page.tsx - Navigate directly to:
http://localhost:3000/admin/setup
If you encounter any issues:
- Check the browser console for errors
- Check the terminal for server errors
- Verify your MongoDB connection is working
- Make sure Clerk authentication is configured correctly