You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When using the openapi-fetch client in Next.js 14.2.4's middleware.ts file, it causes the app to error
Client Error
Server Error
Reproduction
This can be reproduced by using the openapi-fetch client in the middleware.ts file of Next.js. The error does not occur if you use the standalone fetch client
Causes Error:
// Located in another file
const api = createClient<paths>({
baseUrl: 'https://localhost:5000',
});
export default async function middleware(request: NextRequest) {
await api.GET('/api/v1/auth/security');
return Response.redirect(new URL('/', request.url));
}
The solution of manually replacing the fetch for the request with the standalone fetch does work, and because of the small scope of where this error occurs it is not a bad solution. However, since that issue mentioned a fix being merged in, and the follow up mentions specifically that the GET requests are fine, which mine is not, I was unsure if this may be a separate but related issue. However, if you do believe it is a duplicate of the same issue mentioned there, then this issue can be closed as a duplicate.
Description
When using the openapi-fetch client in Next.js 14.2.4's
middleware.ts
file, it causes the app to errorClient Error
![image](https://private-user-images.githubusercontent.com/13159212/341901965-c76538e0-2f0c-4642-af6e-d7803c2abdd2.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MTk4NDg3ODAsIm5iZiI6MTcxOTg0ODQ4MCwicGF0aCI6Ii8xMzE1OTIxMi8zNDE5MDE5NjUtYzc2NTM4ZTAtMmYwYy00NjQyLWFmNmUtZDc4MDNjMmFiZGQyLnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNDA3MDElMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjQwNzAxVDE1NDEyMFomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPTA3ODEzMWY2ZGIxNzU2MjhjZTQxZGZiNThlMmJkOWYwYWE3MGM4NGNlMGUyOWNiYzNjODU5MDAxMGY1YjRiMDMmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0JmFjdG9yX2lkPTAma2V5X2lkPTAmcmVwb19pZD0wIn0.W9paHetH81F7mfxqsxXY1GUYhIAflpxFlcV9aS2hFkQ)
Server Error
![image](https://private-user-images.githubusercontent.com/13159212/341901938-76eea27e-652b-4dcf-9c52-4ed55219e5d5.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MTk4NDg3ODAsIm5iZiI6MTcxOTg0ODQ4MCwicGF0aCI6Ii8xMzE1OTIxMi8zNDE5MDE5MzgtNzZlZWEyN2UtNjUyYi00ZGNmLTljNTItNGVkNTUyMTllNWQ1LnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNDA3MDElMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjQwNzAxVDE1NDEyMFomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPWU5NDc4ODI0N2JkOTlmODgzYTJlYzNkMWNlODY2YWVlNGM1YjRlZDZiNmY5YjI5MGQwMjc3ZWVmNzI5YmVkZTEmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0JmFjdG9yX2lkPTAma2V5X2lkPTAmcmVwb19pZD0wIn0.7MZ0BJPGUieDyYF0_OolopSFumHVjzTV1j0JPV7tWio)
Reproduction
This can be reproduced by using the openapi-fetch client in the
middleware.ts
file of Next.js. The error does not occur if you use the standalone fetch clientCauses Error:
Works:
I made a sandbox using the latest version of Next.js showing this error occurring with a very minimal setup:
Sandbox Reproduction
Expected result
Should be able to use openapi-fetch in
middleware.ts
Checklist
The text was updated successfully, but these errors were encountered: