Admin Setup
Configure admin access and start managing your Gully Sports application. This guide covers everything from initial setup to accessing the admin dashboard.
Overview
The admin panel provides comprehensive business management tools:
Core Features
- 📦 Inventory Management - Products, stock levels, pricing
- 🏏 Lane Management - Cricket lanes, pricing tiers, availability
- 📅 Bookings Management - View and manage customer bookings
- 🛍️ Orders Management - Track purchases and order history
- 📊 Dashboard - Overview stats and recent activity
- 💳 Payment Integration - Intuit QuickBooks OAuth management
Quick Setup
Method 1: Environment Variable (Recommended)
The easiest way to set up admin access:
-
Get Your Supabase User ID
- Sign up/sign in to your application
- Open browser developer tools → Console
- Run:
localStorage.getItem('supabase.auth.token') - Find your
user.idin the JWT
-
Add to Environment Variables
# .env.local
ADMIN_USER_IDS="user-id-1,user-id-2,user-id-3"
Multiple admin IDs should be comma-separated.
- Restart Development Server
npm run dev
- Access Admin Panel
- Navigate to
/admin - You should now have admin access!
- Navigate to
Navigate to /api/admin/intuit/status while logged in - it will show your user ID in the response.
Method 2: Database Update (Alternative)
If you prefer database-level control:
-
Connect to CockroachDB
- Use Prisma Studio:
npx prisma studio - Or connect directly via SQL client
- Use Prisma Studio:
-
Update User Role
UPDATE "User"
SET role = 'ADMIN'
WHERE email = 'your-email@example.com';
- Verify
SELECT id, email, role, name
FROM "User"
WHERE role = 'ADMIN';
Admin Panel Structure
/admin
├── / (Dashboard)
│ ├── Overview statistics
│ ├── Quick actions
│ └── Recent activity
│
├── /inventory
│ ├── Product list with images
│ ├── Add/Edit/Delete products
│ ├── Stock management
│ └── Product image uploads
│
├── /bookings
│ ├── View all bookings
│ ├── Booking details
│ └── Customer information
│
├── /orders
│ ├── View all orders
│ ├── Order details
│ └── Payment status
│
└── /lanes
├── View all cricket lanes
├── Add/Edit/Delete lanes
├── Pricing management
└── Availability settings
First Login
Step 1: Sign In
- Navigate to
/login - Sign in with your configured admin account
- Use Google OAuth or email/password
Step 2: Verify Access
- Check navigation header for admin links
- Navigate to
/admin - You should see the admin dashboard
Step 3: Initial Configuration
Add Products (if using shop features):
- Go to Admin → Inventory
- Click "Add Product"
- Fill in product details
- Upload product images
- Set stock levels
Add Cricket Lanes (if using lane rental):
- Go to Admin → Lane Management
- Click "Add Lane"
- Configure pricing tiers
- Set availability
Configure Payments:
- See Payment Integration Guide
- Choose Intuit or Square
- Complete OAuth setup (for Intuit)
Security Features
Authentication
- Supabase Auth - Enterprise-grade authentication
- Session Management - Secure session handling
- OAuth Support - Google, GitHub, and more
Authorization
- Role-Based Access - Only
ADMINrole can access admin routes - Server-Side Checks - All admin API routes verify authorization
- Client-Side Protection - Admin UI hidden for non-admin users
- Middleware Protection - Next.js middleware guards admin routes
Best Practices
- ✅ Use unique, strong passwords
- ✅ Enable 2FA in Supabase dashboard
- ✅ Regularly audit admin users
- ✅ Use separate accounts for dev/prod
- ✅ Never share admin credentials
- ✅ Rotate access tokens periodically
API Endpoints
All admin endpoints require authentication and admin role.
Products
GET / api / admin / products; // List all products
POST / api / admin / products; // Create product
GET / api / admin / products / [id]; // Get single product
PUT / api / admin / products / [id]; // Update product
DELETE / api / admin / products / [id]; // Delete product
Product Images
GET / api / admin / products / [id] / images; // List product images
POST / api / admin / products / [id] / images; // Add image
PATCH / api / admin / products / [id] / images / [imageId]; // Update image
DELETE / api / admin / products / [id] / images / [imageId]; // Delete image
Lanes
GET / api / admin / lanes; // List all lanes
POST / api / admin / lanes; // Create lane
GET / api / admin / lanes / [id]; // Get single lane
PUT / api / admin / lanes / [id]; // Update lane
DELETE / api / admin / lanes / [id]; // Delete lane
Upload
POST / api / admin / upload; // Get signed upload URL
Troubleshooting
Cannot Access Admin Panel
Issue: 403 Forbidden or redirected to home
Solutions:
- Verify user ID is in
ADMIN_USER_IDS - Check that you're logged in
- Restart dev server after changing env vars
- Clear browser cache and cookies
- Check browser console for errors
Admin Nav Not Showing
Issue: Logged in but no admin links in navigation
Solutions:
- Refresh the page
- Sign out and sign back in
- Verify
ADMIN_USER_IDSformat (comma-separated, no spaces) - Check that auth session is valid
Database Connection Issues
Issue: Admin operations fail with database errors
Solutions:
- Verify
DATABASE_URLin.env.local - Ensure CockroachDB cluster is running
- Run
npx prisma generateto refresh client - Check database migrations are applied
Image Upload Fails
Issue: Cannot upload product images
Solutions:
- Verify
BLOB_READ_WRITE_TOKENis set - Check Vercel Blob storage is configured
- Ensure file size is under 4.5MB
- Check browser console for errors
Advanced Configuration
Custom Admin Roles
Extend the role system for fine-grained permissions:
// prisma/schema.prisma
enum UserRole {
USER
ADMIN
SUPER_ADMIN // Full access
MANAGER // Limited admin access
}
Audit Logging
Track admin actions for compliance:
// utils/adminAudit.ts
export async function logAdminAction(
userId: string,
action: string,
details: object
) {
await prisma.auditLog.create({
data: {
userId,
action,
details,
timestamp: new Date(),
},
});
}
Custom Dashboard Widgets
Add business-specific metrics to the dashboard:
// app/admin/AdminDashboardClient.tsx
const customMetrics = {
todayRevenue: await calculateRevenue("today"),
activeBookings: await countActiveBookings(),
topProducts: await getTopSellingProducts(5),
};
Next Steps
- Admin Dashboard - Explore dashboard features
- Authentication - Deep dive into auth system
- Payment Setup - Configure payment processing
- Product Images - Set up image management
Need help? Check the Admin Authentication Guide or create an issue on GitHub.