mirror of
https://github.com/mudabbir-ahmad/peworkshop.git
synced 2026-10-07 19:50:20 +00:00
fixed a bit
This commit is contained in:
1 parent
c62413eafa
commit
4ed0480d08
10 files changed
+138
-149
No files matched your search
@@ -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 }
|
||||
);
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user