Next.js Discord

Discord Forum

Language routes and authentication - Next v14 + Auth v5

Unanswered
Judder posted this in #help-forum
Open in Discord
Avatar
Hey! So in my case I'm wondering how to set up my authentication flow, I'm using next 14 and auth v5, so it's not documented completely yet. My login pages are inside the [lang] folder, and my api route is not inside it, for which I have set up this rewrite for my api routes: async rewrites() { return [ { // Match all API requests with a language prefix source: '/:lang/api/:path*', // Redirect them to the standard API route without the language prefix destination: '/api/:path*', // The path and query parameters will be forwarded }, ] },
but when I login, the redirectUri takes the lang parameter with it, making it have (currently) five different possible callbacks. For example github doesn't allow more than one callback url. So I was wondering if you knew how I could modify the redirectUri to not include the language parameter, or if there's some other way I should do this.

@Satin Angora, thanks for replying to my previous message 🙂

2 Replies

Avatar
I want to add a thing here I tried, which is adding the redirect_uri in the auth config, but that leads to ERR_TOO_MANY_REDIRECTS when logging in.
Image
Avatar
I think I might of solved this with 3 lines in my middleware.

if (pathname.startsWith('/api/auth/callback')) { return NextResponse.next(request.nextUrl) }