fixed a bit

This commit is contained in:
bobbert committed 2025-03-12 01:46:45 +00:00
1 parent c62413eafa
commit 4ed0480d08
10 files changed
+138 -149

No files matched your search

+23 -12
View File
@@ -1,29 +1,40 @@
// app/(main)/team/[teamId]/route.js
import { queryOne, query } from "../../../../lib/db";
import { getServerSession } from "next-auth/next";
import { authOptions } from "../../../api/auth/[...nextauth]/route";
import { redirect } from "next/navigation";
import { getServerSession } from "next-auth/next";
import { authOptions } from "@/app/api/auth/[...nextauth]/route";
import { queryOne, query } from "@/lib/db";
export async function GET(request, context) {
export async function GET(_, context) {
const session = await getServerSession(authOptions);
if (!session) {
// Redirect to login page instead of returning JSON
return redirect("/login");
}
try {
const { teamId } = context.params;
const params = await context.params;
const teamId = params.teamId;
// Instead of returning JSON, we should let the page component handle rendering
// This route.js file should only be used for API endpoints, not page rendering
const team = await queryOne("SELECT * FROM teams WHERE id = ?", [teamId]);
// Redirect to the page component
return redirect(`/team/${teamId}`);
if (!team) {
return new Response(
JSON.stringify({ success: false, error: "Team not found" }),
{ status: 404 }
);
}
const members = await query(
"SELECT id, username FROM users WHERE team_id = ?",
[teamId]
);
return new Response(JSON.stringify({ success: true, team, members }), {
status: 200,
});
} catch (error) {
console.error("Team fetch error:", error);
return new Response(
JSON.stringify({ error: "Failed to fetch team details" }),
JSON.stringify({ success: false, error: "Failed to fetch team" }),
{ status: 500 }
);
}