feat: apply various dashboard and auth fixes including demo trials, settings UI, and signup options

This commit is contained in:
2026-09-23 16:38:49 +05:30
parent 86a2749360
commit 1d9cdd3f33
18 changed files with 435 additions and 147 deletions

View File

@@ -3,20 +3,48 @@ import { NextRequest } from 'next/server';
import { join } from 'path';
import { readFileSync } from 'fs';
export async function GET(req: NextRequest) {
export async function GET(req: NextRequest, { params }: { params: Promise<{ userId: string }> }) {
try {
const { searchParams } = new URL(req.url);
const { userId } = await params;
// Read metrics
const score = searchParams.get('score') || '0 / 0';
const accuracy = searchParams.get('accuracy') || '0%';
const qs = searchParams.get('qs') || '0';
const rank = searchParams.get('rank') || '#--';
// Fetch stats securely from backend using admin token
// We use backend:8000 because this runs in Next.js docker container
const backendUrl = process.env.NEXT_PUBLIC_API_URL?.includes('localhost')
? 'http://backend:8000'
: process.env.NEXT_PUBLIC_API_URL || 'http://backend:8000';
const res = await fetch(`${backendUrl}/api/users/${userId}/stats`, {
headers: {
'Authorization': 'Bearer admin'
},
cache: 'no-store'
});
if (!res.ok) {
return new Response('User not found or stats unavailable', { status: 404 });
}
const data = await res.json();
// Read metrics from backend response
const score = `${data.score} / ${data.total_marks || 300}`;
const accuracy = data.accuracy || '0%';
const qs = (data.total_questions || 0).toString();
const rank = data.city_rank ? `#${data.city_rank}` : '#--';
// Read user info
const name = searchParams.get('name') || 'Student';
const target = searchParams.get('target') || 'JEE';
const plan = searchParams.get('plan') || 'Free';
const name = data.name || 'Student';
// Format target correctly (e.g. JEE_MAIN -> JEE)
let target = data.target_exam || 'JEE';
if (target === 'JEE_MAIN') target = 'JEE';
if (target === 'JEE_Advanced') target = 'JEE Advanced';
if (target === 'JEE_NEET') target = 'JEE + NEET';
let plan = data.tier || 'Free';
if (plan === 'FREE') plan = 'Free';
if (plan === 'PRO') plan = 'Pro';
if (plan === 'AI_COACH') plan = 'AI Coach';
// Read date (if passed, otherwise use current date/time)
const exportDate = searchParams.get('date') || new Intl.DateTimeFormat('en-IN', {