Skip to main content

Overview

The OpenSight admin panel is a Next.js application located in apps/admin/ that provides platform administrators with tools to manage users, monitor system health, and view analytics.

Accessing the Admin Panel

The admin panel is a separate application from the main web app:
  • Main App: User-facing dashboard (apps/web)
  • Admin Panel: Platform management (apps/admin)
Admin access requires an entry in the admin_users table. Contact your system administrator for access.

Authentication

Admin authentication is handled separately from regular user authentication:
apps/admin/app/api/auth/login/route.ts
// Admin login endpoint
POST /api/auth/login
{
  "email": "[email protected]",
  "password": "secure_password"
}
Admin sessions are verified using the verifySession() function defined in apps/admin/lib/auth.ts.

Dashboard Overview

The main dashboard (apps/admin/app/(dashboard)/page.tsx) displays key platform metrics:

System Statistics

Total Users

Count of all registered users in the platform

Brands

Total number of brands being monitored

Admins

Number of admin accounts with panel access

System Health

Overall platform operational status

Statistics Implementation

apps/admin/app/(dashboard)/page.tsx
async function getStats() {
  const [userCount] = await db.select({ value: count() }).from(users);
  const [brandCount] = await db.select({ value: count() }).from(brands);
  const [adminCount] = await db.select({ value: count() }).from(adminUsers);

  return {
    users: userCount.value,
    brands: brandCount.value,
    admins: adminCount.value,
  };
}

User Management

The Users page (apps/admin/app/(dashboard)/users/page.tsx) provides a complete view of registered users.

User List Features

  • User Details: Name, email, plan tier, verification status
  • Sorting: Users ordered by creation date (newest first)
  • Plan Badges: Visual indicators for Free, Starter, and Growth plans
  • Verification Status: Email verification tracking
  • Join Date: Account creation timestamp

User Data Structure

apps/admin/app/(dashboard)/users/page.tsx
async function getUsers() {
  return db
    .select({
      id: users.id,
      email: users.email,
      fullName: users.fullName,
      emailVerified: users.emailVerified,
      planId: users.planId,
      createdAt: users.createdAt,
    })
    .from(users)
    .orderBy(desc(users.createdAt))
    .limit(50);
}
The user list is currently limited to the 50 most recent users. For full user management, consider implementing pagination.

Reports

The Reports page (apps/admin/app/(dashboard)/reports/page.tsx) is designed for analytics and system metrics.
The Reports section is currently under construction. Future features will include:
  • User activity tracking
  • Brand performance metrics
  • API usage statistics
  • Subscription revenue analytics

Settings

The Settings page (apps/admin/app/(dashboard)/settings/page.tsx) will provide platform configuration options.
Settings features are planned to include:
  • Admin user management
  • System configuration
  • Feature flags
  • Integration settings

Admin Panel Structure

The admin panel uses a dashboard layout with sidebar navigation:
  • AdminHeader (components/admin-header.tsx): Top navigation bar with user menu
  • AdminSidebar (components/admin-sidebar.tsx): Left sidebar with main navigation links

Available Routes

RoutePurposeStatus
/Dashboard overview✅ Active
/usersUser management✅ Active
/reportsAnalytics and reporting🚧 Planned
/settingsSystem settings🚧 Planned

Database Access

The admin panel connects directly to the database using Drizzle ORM:
apps/admin/lib/db.ts
import { drizzle } from 'drizzle-orm/postgres-js';
import { users, brands, adminUsers } from '@opensight/db';

export const db = drizzle(...);
Admin panel queries have direct database access. Always verify admin authentication before executing queries.

Security Considerations

Authentication Requirements

  1. Session Verification: All admin routes check authentication via verifySession()
  2. Admin Table: Only users in admin_users table can access the panel
  3. Separate Sessions: Admin sessions are isolated from regular user sessions

Best Practices

  • Never expose admin endpoints publicly
  • Use strong passwords for admin accounts
  • Implement IP whitelisting for production deployments
  • Regularly audit admin user access

Seeding Admin Users

For development, you can seed an admin user using:
POST /api/auth/seed
This endpoint is defined in apps/admin/app/api/auth/seed/route.ts.
The seed endpoint should be disabled in production environments.

Plans & Pricing

View subscription tiers and user plan limits

Integrations

Configure platform integrations and services

Build docs developers (and LLMs) love