Admin System
Admin dashboard and management features
Admin System
The Admin System provides complete control over users, orders, content, and AI configuration.
Access
Setting Up Admin Access
-
Set admin email in environment variables:
ADMIN_EMAILS="your-email@example.com,another@example.com" -
Deploy or restart server
-
Sign in with admin email
-
Access admin at
/admin
Multiple admins supported - separate emails with commas.
Admin Dashboard
Location
/admin
Features
Dashboard Overview:
- Total users count
- Paid orders count
- System posts count
- User feedbacks count
- Users growth chart (90 days)
- Orders trend chart (90 days)
Navigation:
- Dashboard - Overview and analytics
- Users - User management
- Orders - Order management
- Posts - Content management
- Feedbacks - User feedback
- AI Configuration - AI provider keys
User Management
Location
/admin/users
Features
User List:
- View all registered users
- See user avatar, email, nickname
- Check registration date
- View user UUID
User Data:
- Total credits
- Order history
- Referral stats
- API keys
Common Tasks
Find user by email:
SELECT * FROM users WHERE email = 'user@example.com';
View user's orders:
SELECT * FROM orders WHERE user_uuid = 'xxx';
Add credits to user:
import { increaseCredits, CreditsTransType } from "@/services/credit";
await increaseCredits({
user_uuid: "user-uuid",
trans_type: CreditsTransType.SystemAdd,
credits: 500,
expired_at: "2026-12-31T23:59:59Z",
});
Order Management
Location
/admin/orders
Features
Order List:
- View all paid orders
- Filter by status
- See order details
- Track revenue
Order Information:
- Order number
- Customer email
- Product name
- Amount paid
- Payment date
- Subscription ID (if applicable)
Refund Process
Refunds are handled in Stripe Dashboard:
- Go to Stripe Dashboard
- Find the payment
- Click Refund
- Enter amount (full or partial)
- Confirm refund
Note: Update order status manually in database if needed:
UPDATE orders
SET status = 'refunded'
WHERE order_no = 'order_xxx';
Content Management
Posts
Location: /admin/posts
Features:
- Create new blog posts
- Edit existing posts
- Delete posts
- Publish/unpublish
- Multi-language support
Create Post:
- Click Add Post
- Enter title, description
- Write content (Markdown)
- Set slug (URL)
- Choose language
- Set status (draft/published)
- Save
Edit Post:
- Click Edit on post row
- Modify content
- Save changes
Feedbacks
Location: /admin/feedbacks
View user feedback:
- User avatar and name
- Feedback content
- Rating (1-5 stars)
- Submission date
- Link to view user details
Managing Feedback:
- Review for product improvements
- Identify issues
- Engage with users
- Feature requests
AI Configuration
Location
/admin/ai-config
Features
Manage AI Provider Keys:
- Add/edit/delete provider configurations
- Enable/disable providers
- View masked API keys
- Test provider connectivity
Adding a Provider
- Click provider name (e.g., openai)
- Enter API key
- Add model config (JSON, optional):
{ "max_tokens": 4096, "temperature": 0.7 } - Toggle Enabled
- Click Save
Editing Provider
- Click Edit Provider on existing provider
- Update API key (leave blank to keep existing)
- Modify configuration
- Save
Deleting Provider
- Click delete icon (trash bin)
- Confirm deletion
- System falls back to environment variable if set
Provider Priority
- Database (configured in AI Config) - Used first
- Environment Variable - Fallback
- None - Provider unavailable
Cache: API keys are cached for 5 minutes for performance.
System Monitoring
Metrics to Watch
User Growth:
SELECT DATE(created_at) as date, COUNT(*) as new_users
FROM users
WHERE created_at > NOW() - INTERVAL '30 days'
GROUP BY DATE(created_at)
ORDER BY date;
Revenue Tracking:
SELECT DATE(paid_at) as date,
SUM(amount) / 100 as revenue_usd,
COUNT(*) as orders
FROM orders
WHERE status = 'paid'
AND paid_at > NOW() - INTERVAL '30 days'
GROUP BY DATE(paid_at);
AI Usage:
SELECT provider, ai_type, COUNT(*) as generations,
SUM(credits_cost) as total_credits
FROM generations
WHERE status = 'completed'
AND created_at > NOW() - INTERVAL '7 days'
GROUP BY provider, ai_type;
Active Subscriptions:
SELECT product_id, interval, COUNT(*) as subscribers
FROM orders
WHERE status = 'paid'
AND sub_id IS NOT NULL
AND sub_id != ''
GROUP BY product_id, interval;
Security
Admin Authentication
Only users in ADMIN_EMAILS can access /admin.
Verification:
// In src/app/[locale]/(admin)/layout.tsx
const adminEmails = process.env.ADMIN_EMAILS?.split(",");
if (!adminEmails?.includes(userInfo?.email)) {
return <Empty message="No access" />;
}
Best Practices
- Use strong admin passwords
- Enable 2FA on admin accounts
- Audit admin actions (add logging)
- Restrict admin access to trusted emails only
- Review admin activity regularly
Common Admin Tasks
Reset User Password
Users can reset via NextAuth. For manual reset:
- User must use "Forgot Password" in OAuth provider
- Or revoke session and force re-login
Ban User
-- Option 1: Delete user account
DELETE FROM users WHERE uuid = 'user-uuid';
-- Option 2: Revoke affiliate status
UPDATE users SET is_affiliate = false WHERE uuid = 'user-uuid';
-- Option 3: Zero out credits
UPDATE credits SET left_credits = 0 WHERE user_uuid = 'user-uuid';
Approve Affiliate Commission
UPDATE affiliates
SET status = 'approved'
WHERE id = 123;
Grant Credits
Via API or directly:
INSERT INTO credits_trans (user_uuid, trans_type, credits, expired_at)
VALUES ('user-uuid', 'system_add', 1000, '2026-12-31T23:59:59Z');
UPDATE credits
SET left_credits = left_credits + 1000,
total_credits = total_credits + 1000
WHERE user_uuid = 'user-uuid';
Troubleshooting
Can't access admin panel
Check:
- Your email is in
ADMIN_EMAILS - Environment variable is set correctly
- Redeploy after adding
ADMIN_EMAILS - Sign out and sign in again
Admin pages show "No access"
Solution:
# Check admin emails configuration
ADMIN_EMAILS="your-email@example.com"
# Restart server
pnpm dev
AI Config not saving
Check:
- Database connection is working
ai_provider_keystable exists (runpnpm db:push)- Check browser console for errors
- Verify API key format is correct
Next Steps
- User Management - Detailed user admin
- AI Configuration - AI setup
- Database - Direct database access
- Troubleshooting - Common issues