QuiiBz / next-international

Type-safe internationalization (i18n) for Next.js
https://next-international.vercel.app
MIT License
1.28k stars 59 forks source link

TypeError : Cannot read properties of undefined (reading 'get') at middleware #376

Closed SaddamMohsen closed 6 months ago

SaddamMohsen commented 6 months ago

i set up everything as the doc and it works perfectly until i connect the frontend with backend using API backend url i get this error

⨯ node_modules\next-international\dist\app\middleware\index.js (78:45) @ get ⨯ Cannot read properties of undefined (reading 'get') Screenshots image

About

Additional context I add the next-auth middleware with next-international middleware

QuiiBz commented 6 months ago

Looking at your error, this seems to be caused by something else - could you share your whole middleware file?

SaddamMohsen commented 6 months ago

Looking at your error, this seems to be caused by something else - could you share your whole middleware file?

i think it was caused by this lines of code I used this code to remove the locale from the URL to check if the URL is allowed or not. Therefore, I cannot do this separately for each language. So I removed the locale, checked the access permissions, and then added the locale back. if ((langs.includes(nextUrl.pathname.split('/')[1]))) { // Remove the local segment

//isSegmentRemoved = 1;
nextUrl.pathname = nextUrl.pathname.replace(/^\/(en|ar)\/?/, '');

return NextResponse.rewrite(nextUrl);

}

i don't know how but now it is working but without return

QuiiBz commented 6 months ago

I'll close this issue for now since it's not caused by next-international. Happy to help further if you can share the full middleware code!