other
This commit is contained in:
@@ -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));
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user