"use client" import React from 'react' import { useAuth } from '@/lib/auth-context' import { LoginForm } from './login-form' interface ProtectedRouteProps { children: React.ReactNode requiredRole?: 'admin' | 'user' fallback?: React.ReactNode } export function ProtectedRoute({ children, requiredRole, fallback }: ProtectedRouteProps) { const { isAuthenticated, isLoading, user, authEnabled } = useAuth() // If authentication is not enabled, allow access if (!authEnabled) { return <>{children} } if (isLoading) { return (

Loading...

) } if (!isAuthenticated) { if (fallback) { return <>{fallback} } return (

Stable Diffusion

Please sign in to continue

) } // Check role requirements if (requiredRole && user?.role !== requiredRole) { return (

Access Denied

You don't have permission to access this page.

) } return <>{children} } // Higher-order component for protecting routes export function withAuth

( Component: React.ComponentType

, options?: { requiredRole?: 'admin' | 'user' } ) { return function AuthenticatedComponent(props: P) { return ( ) } }