Update middleware.ts
This commit is contained in:
@@ -10,15 +10,17 @@ export async function middleware(req: NextRequest) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// Need to use a full URL for server-side fetch
|
// Use SERVER_API_URL which should be set to a working URL in the .env files
|
||||||
const baseUrl = req.nextUrl.origin + '/api';
|
const apiUrl = process.env.SERVER_API_URL || 'https://internal-api.inboxi.ng/api';
|
||||||
|
console.log(`Using API URL for authentication: ${apiUrl}/auth/me`);
|
||||||
|
|
||||||
const res = await fetch(`${baseUrl}/auth/me`, {
|
const res = await fetch(`${apiUrl}/auth/me`, {
|
||||||
method: "GET",
|
method: "GET",
|
||||||
headers: {
|
headers: {
|
||||||
"Content-Type": "application/json",
|
"Content-Type": "application/json",
|
||||||
Authorization: `Bearer ${token}`,
|
Authorization: `Bearer ${token}`,
|
||||||
},
|
},
|
||||||
|
// No Node.js-specific options as middleware runs in Edge Runtime
|
||||||
});
|
});
|
||||||
|
|
||||||
if (!res.ok) {
|
if (!res.ok) {
|
||||||
|
|||||||
Reference in New Issue
Block a user