mirror of
https://github.com/mudabbir-ahmad/peworkshop.git
synced 2026-10-08 03:50:21 +00:00
FIX OF ALL ISSUES WITH LOG IN PAGE. EVERYTHING TO THE POINT OF TESTING THE MAP WORKS SO FAR.
This commit is contained in:
1 parent
84f010cb87
commit
c79a9636a7
10 files changed
+228
-233
No files matched your search
@@ -1,24 +1,27 @@
|
||||
import { redirect } from "next/navigation";
|
||||
import { cookies } from "next/headers";
|
||||
import { verifyToken } from "@/app/api/auth/[...nextauth]/route";
|
||||
import { getToken } from "next-auth/jwt";
|
||||
|
||||
export async function GET(_, context) {
|
||||
export async function GET(request, context) {
|
||||
try {
|
||||
// Use our custom token verification instead of getServerSession
|
||||
const cookieStore = await cookies();
|
||||
const sessionToken = cookieStore.get("next-auth.session-token")?.value;
|
||||
|
||||
if (!sessionToken) {
|
||||
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");
|
||||
}
|
||||
|
||||
const userData = verifyToken(sessionToken);
|
||||
if (!userData) {
|
||||
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}`);
|
||||
}
|
||||
|
||||
// Instead of returning JSON, redirect to the page component
|
||||
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");
|
||||
|
||||
Reference in new issue
Block a user