Spaces:
Sleeping
Sleeping
v4.1: Fix /api/me — Infinity → 999999 in JSON, add all capability flags
Browse files- web/app/api/me/route.ts +30 -8
web/app/api/me/route.ts
CHANGED
|
@@ -5,7 +5,7 @@ import { createClient } from "@/lib/supabase/server";
|
|
| 5 |
* GET /api/me
|
| 6 |
* Returns the current user's profile from DB.
|
| 7 |
* Used by client components (analyze page, etc.) to determine plan, role, usage.
|
| 8 |
-
*
|
| 9 |
*/
|
| 10 |
export async function GET(req: NextRequest) {
|
| 11 |
try {
|
|
@@ -19,17 +19,27 @@ export async function GET(req: NextRequest) {
|
|
| 19 |
role: "user",
|
| 20 |
isAdmin: false,
|
| 21 |
analyses_this_month: 0,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 22 |
});
|
| 23 |
}
|
| 24 |
|
| 25 |
const { data: profile } = await supabase
|
| 26 |
.from("profiles")
|
| 27 |
-
.select("plan, role, is_banned, analyses_this_month, full_name, email")
|
| 28 |
.eq("id", user.id)
|
| 29 |
.single();
|
| 30 |
|
| 31 |
const plan = profile?.plan || "free";
|
| 32 |
const role = profile?.role || "user";
|
|
|
|
|
|
|
|
|
|
|
|
|
| 33 |
|
| 34 |
return NextResponse.json({
|
| 35 |
authenticated: true,
|
|
@@ -38,14 +48,20 @@ export async function GET(req: NextRequest) {
|
|
| 38 |
full_name: profile?.full_name || "",
|
| 39 |
plan,
|
| 40 |
role,
|
| 41 |
-
isAdmin
|
| 42 |
is_banned: profile?.is_banned || false,
|
| 43 |
analyses_this_month: profile?.analyses_this_month || 0,
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 49 |
});
|
| 50 |
} catch (error) {
|
| 51 |
return NextResponse.json({
|
|
@@ -54,6 +70,12 @@ export async function GET(req: NextRequest) {
|
|
| 54 |
role: "user",
|
| 55 |
isAdmin: false,
|
| 56 |
analyses_this_month: 0,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 57 |
});
|
| 58 |
}
|
| 59 |
}
|
|
|
|
| 5 |
* GET /api/me
|
| 6 |
* Returns the current user's profile from DB.
|
| 7 |
* Used by client components (analyze page, etc.) to determine plan, role, usage.
|
| 8 |
+
* Admin gets FULL access to everything — no limits, no restrictions.
|
| 9 |
*/
|
| 10 |
export async function GET(req: NextRequest) {
|
| 11 |
try {
|
|
|
|
| 19 |
role: "user",
|
| 20 |
isAdmin: false,
|
| 21 |
analyses_this_month: 0,
|
| 22 |
+
scan_limit: 10,
|
| 23 |
+
can_upload: false,
|
| 24 |
+
can_compare: false,
|
| 25 |
+
can_export_pdf: false,
|
| 26 |
+
can_chat: false,
|
| 27 |
+
can_redline_llm: false,
|
| 28 |
});
|
| 29 |
}
|
| 30 |
|
| 31 |
const { data: profile } = await supabase
|
| 32 |
.from("profiles")
|
| 33 |
+
.select("plan, role, is_banned, analyses_this_month, full_name, email, team_id, created_at")
|
| 34 |
.eq("id", user.id)
|
| 35 |
.single();
|
| 36 |
|
| 37 |
const plan = profile?.plan || "free";
|
| 38 |
const role = profile?.role || "user";
|
| 39 |
+
const isAdmin = role === "admin";
|
| 40 |
+
|
| 41 |
+
// Admin gets EVERYTHING — no limits, no restrictions, period.
|
| 42 |
+
const hasFullAccess = isAdmin || plan !== "free";
|
| 43 |
|
| 44 |
return NextResponse.json({
|
| 45 |
authenticated: true,
|
|
|
|
| 48 |
full_name: profile?.full_name || "",
|
| 49 |
plan,
|
| 50 |
role,
|
| 51 |
+
isAdmin,
|
| 52 |
is_banned: profile?.is_banned || false,
|
| 53 |
analyses_this_month: profile?.analyses_this_month || 0,
|
| 54 |
+
team_id: profile?.team_id || null,
|
| 55 |
+
created_at: profile?.created_at || null,
|
| 56 |
+
// Use 999999 instead of Infinity (not valid JSON)
|
| 57 |
+
scan_limit: isAdmin ? 999999 : plan === "free" ? 10 : 999999,
|
| 58 |
+
can_upload: hasFullAccess,
|
| 59 |
+
can_compare: hasFullAccess,
|
| 60 |
+
can_export_pdf: hasFullAccess,
|
| 61 |
+
can_chat: hasFullAccess,
|
| 62 |
+
can_redline_llm: hasFullAccess,
|
| 63 |
+
can_api_keys: hasFullAccess,
|
| 64 |
+
can_team: isAdmin || plan === "team",
|
| 65 |
});
|
| 66 |
} catch (error) {
|
| 67 |
return NextResponse.json({
|
|
|
|
| 70 |
role: "user",
|
| 71 |
isAdmin: false,
|
| 72 |
analyses_this_month: 0,
|
| 73 |
+
scan_limit: 10,
|
| 74 |
+
can_upload: false,
|
| 75 |
+
can_compare: false,
|
| 76 |
+
can_export_pdf: false,
|
| 77 |
+
can_chat: false,
|
| 78 |
+
can_redline_llm: false,
|
| 79 |
});
|
| 80 |
}
|
| 81 |
}
|