A modern online coding platform with real-time code execution, problem solving, and advanced anti-cheating mechanisms.
- Real-time Code Execution - Execute code in multiple languages (JavaScript, Python, Java, C++)
- Problem Solving Platform - Solve coding problems with test case validation
- User Authentication - Secure authentication with Clerk
- Submission History - Track all your code submissions and results
- Responsive Design - Works seamlessly on desktop and mobile devices
Automatic code submission when users attempt to cheat by:
- β Switching to another browser tab
- β Switching to another application (Alt+Tab)
- β Closing or refreshing the page
- β Minimizing the browser window
How it works:
- Event listeners detect when users leave the problem page
- Code is automatically submitted to prevent cheating
- Submissions are marked with
autoSubmitted: trueflag - Works even with empty or incomplete code
- Toast notifications inform users of auto-submission
Implementation Details:
- Uses
visibilitychange,blur, andbeforeunloadevents - Prevents multiple simultaneous submissions
- Handles promise rejections gracefully
- Debug logging for troubleshooting
- Framework: Next.js 16 (App Router, Turbopack)
- Language: TypeScript
- Authentication: Clerk
- Database: Supabase (PostgreSQL)
- Code Execution: Judge0 API
- Styling: Tailwind CSS
- UI Components: Radix UI, shadcn/ui
- Node.js 18+ and npm
- Supabase account
- Clerk account
- Judge0 API access (local or hosted)
git clone <repository-url>
cd editornpm installCreate a .env file in the root directory:
# Clerk Authentication
NEXT_PUBLIC_CLERK_PUBLISHABLE_KEY=your_clerk_publishable_key
CLERK_SECRET_KEY=your_clerk_secret_key
# Supabase
NEXT_PUBLIC_SUPABASE_URL=your_supabase_url
NEXT_PUBLIC_SUPABASE_ANON_KEY=your_supabase_anon_key
SUPABASE_SERVICE_ROLE_KEY=your_supabase_service_role_key
# Judge0 API
JUDGE0_API_URL=http://localhost:2358
JUDGE0_API_KEY=your_judge0_api_keyRun the SQL schema in Supabase:
# Import supabase_schema_fixed.sql into your Supabase projectnpm run devOpen http://localhost:3000 to see the application.
editor/
βββ app/ # Next.js app directory
β βββ api/ # API routes
β β βββ execute/ # Code execution endpoint
β β βββ submissions/ # Submission management
β βββ problems/ # Problem pages
β βββ page.tsx # Home page
βββ components/ # React components
β βββ problem-solver/ # Problem solving interface
β βββ code-editor/ # Code editor component
β βββ ui/ # UI components (shadcn)
βββ lib/ # Utility functions
β βββ judge0/ # Judge0 API client
β βββ supabase/ # Supabase client
βββ types/ # TypeScript type definitions
File: components/problem-solver/ProblemSolver.tsx
// Event listeners for auto-submit
useEffect(() => {
const handleVisibilityChange = () => {
if (document.hidden) {
autoSubmit('tab switch').catch(err => console.error(err));
}
};
const handleBlur = () => {
autoSubmit('app switch').catch(err => console.error(err));
};
const handleBeforeUnload = (e: BeforeUnloadEvent) => {
autoSubmit('page close').catch(err => console.error(err));
};
document.addEventListener('visibilitychange', handleVisibilityChange);
window.addEventListener('blur', handleBlur);
window.addEventListener('beforeunload', handleBeforeUnload);
return () => {
document.removeEventListener('visibilitychange', handleVisibilityChange);
window.removeEventListener('blur', handleBlur);
window.removeEventListener('beforeunload', handleBeforeUnload);
};
}, [problem.id, submissionSuccess, pendingSubmission, toast]);Submission API: app/api/submissions/route.ts
POST /api/submissions- Submit code for evaluationGET /api/submissions?problemId=<id>- Get user submissions
Execution API: app/api/execute/route.ts
POST /api/execute- Execute code against test cases
- Sign in to the application
- Navigate to any problem page
- Try one of these actions:
- Switch to another browser tab
- Press Alt+Tab to switch applications
- Try to close the browser tab
- Check console logs for
[AutoSubmit]messages - Verify submission appears in Submissions tab
[Tab Switch] Detected
[AutoSubmit] Called with reason: tab switch
[AutoSubmit] Checking conditions: {pendingSubmission: false, userId: "...", problemId: "..."}
[AutoSubmit] Submitting code...
- Check console logs - Look for
[AutoSubmit]messages - Verify authentication - User must be logged in
- Check network tab - Look for
POST /api/submissionsrequests - Clear browser cache - Force reload with Ctrl+Shift+R
- Expected behavior when submitting empty code
- Judge0 cannot execute empty code
- Submission is still saved to database
# Kill process on port 3000
npx kill-port 3000
# Or use a different port
npm run dev -- -p 3001This project is licensed under the MIT License.
Contributions are welcome! Please feel free to submit a Pull Request.
For support, email your-email@example.com or open an issue in the repository.