import { redirect } from "next/navigation"; import { getToken } from "next-auth/jwt"; export async function GET(request, context) { try { const token = await getToken({ req: request, secret: process.env.NEXTAUTH_SECRET || "your-fallback-secret-should-be-at-least-32-chars", }); if (!token) { return redirect("/login"); } // If the token's teamId matches the requested teamId or the user is admin, redirect accordingly. if ( (token.teamId && parseInt(token.teamId, 10) === parseInt(context.params.teamId, 10)) || token.role === "admin" ) { return redirect(`/${context.params.teamId}`); } // If not, the user is not associated with this team. return redirect("/team-selection"); } catch (error) { console.error("Team route error:", error); return redirect("/team-selection"); } }