feat(auth): enable requireWorkspacePrincipal on individual session GET route to support desktop API keys
This commit is contained in:
@@ -7,18 +7,28 @@
|
||||
* (handled in /stop/route.ts)
|
||||
*/
|
||||
import { NextResponse } from "next/server";
|
||||
import { authSession } from "@/lib/auth/session-server";
|
||||
import { query } from "@/lib/db-postgres";
|
||||
import { requireWorkspacePrincipal } from "@/lib/auth/workspace-auth";
|
||||
import { query, queryOne } from "@/lib/db-postgres";
|
||||
|
||||
export async function GET(
|
||||
_req: Request,
|
||||
request: Request,
|
||||
{ params }: { params: Promise<{ projectId: string; sessionId: string }> }
|
||||
) {
|
||||
try {
|
||||
const { projectId, sessionId } = await params;
|
||||
const session = await authSession();
|
||||
if (!session?.user?.email) {
|
||||
return NextResponse.json({ error: "Unauthorized" }, { status: 401 });
|
||||
|
||||
// 1. Authenticate the Workspace API key or Browser Session
|
||||
const principal = await requireWorkspacePrincipal(request);
|
||||
if (principal instanceof NextResponse) return principal;
|
||||
|
||||
// 2. Fetch user details from principal.userId
|
||||
const userRow = await queryOne<{ id: string; data: any }>(
|
||||
`SELECT id, data FROM fs_users WHERE id = $1 LIMIT 1`,
|
||||
[principal.userId]
|
||||
);
|
||||
const email = userRow?.data?.email;
|
||||
if (!email) {
|
||||
return NextResponse.json({ error: "User email not found" }, { status: 404 });
|
||||
}
|
||||
|
||||
const rows = await query<{
|
||||
@@ -43,7 +53,7 @@ export async function GET(
|
||||
JOIN fs_users u ON u.id = p.user_id
|
||||
WHERE s.id = $1::uuid AND s.project_id::text = $2 AND u.data->>'email' = $3
|
||||
LIMIT 1`,
|
||||
[sessionId, projectId, session.user.email]
|
||||
[sessionId, projectId, email]
|
||||
);
|
||||
|
||||
if (rows.length === 0) {
|
||||
|
||||
Reference in New Issue
Block a user