This commit is contained in:
NotII
2025-03-10 17:39:37 +00:00
parent c08df8919d
commit 20d5559832
69 changed files with 7676 additions and 78 deletions

View File

@@ -10,19 +10,30 @@ export async function middleware(req: NextRequest) {
}
try {
const res = await fetch(`${process.env.NEXT_PUBLIC_API_URL}/auth/me`, {
method: "GET",
// Make sure we use a complete URL with protocol
// When running locally with integrated backend, we need to specify the full URL including protocol
const origin = req.nextUrl.origin;
const authEndpoint = new URL("/api/auth/me", origin).toString();
console.log("Verifying authentication with endpoint:", authEndpoint);
const res = await fetch(authEndpoint, {
method: "GET",
headers: {
"Content-Type": "application/json",
Authorization: `Bearer ${token}`,
},
// Ensure we're not caching authentication checks
cache: 'no-store'
});
if (!res.ok) {
console.error(`Auth check failed with status: ${res.status}`);
return NextResponse.redirect(new URL("/auth/login", req.url));
}
} catch (error) {
console.error("Authentication validation failed:", error);
console.error("Error details:", error instanceof Error ? error.message : 'Unknown error');
return NextResponse.redirect(new URL("/auth/login", req.url));
}