Next.js Discord

Discord Forum

Need help with i18next package config in my project

Unanswered
Japanese jack mackerel posted this in #help-forum
Open in Discord
Japanese jack mackerelOP
So my application has a OAuth service and the callback uri is limited to /auth?code=23..... but when am using the package i cannot redirect as the routes are all either /fr/auth or /en/auth depending the preference. How can i solve this issue.

11 Replies

@Japanese jack mackerel So my application has a OAuth service and the callback uri is limited to /auth?code=23..... but when am using the package i cannot redirect as the routes are all either /fr/auth or /en/auth depending the preference. How can i solve this issue.
you normally have a middleware, that allows you to automatically get the preference. Like that you can return the user to /what/ever/route/you/need/ and the user will be redirected (though middleware) to /fr/what/ever/route/you/need/ or /en/what/ever/route/you/need/ or ...

Do you have a middleware, that handles that?
Japanese jack mackerelOP
import createMiddleware from 'next-intl/middleware';
import { routing } from './i18n/routing';

export default createMiddleware(routing, {
localeDetection: false
});

export const config = {
// Match only internationalized pathnames
matcher: ['/', '/(fr|en)/:path*']
};


i have basic middleware like this one
Japanese jack mackerelOP
yea its supposed to as am passing the routing

import { defineRouting } from 'next-intl/routing';
import { createSharedPathnamesNavigation } from 'next-intl/navigation';

export const routing = defineRouting({
// A list of all locales that are supported
locales: ['en', 'fr'],

// Used when no locale matches
defaultLocale: 'en',
localePrefix: 'never'


});

// Lightweight wrappers around Next.js' navigation APIs
// that will consider the routing configuration
export const { Link, redirect, usePathname, useRouter } =
createSharedPathnamesNavigation(routing);
Japanese jack mackerelOP
yes
@Japanese jack mackerel yes
can you clarify this then:
i cannot redirect as the routes are all either /fr/auth or /en/auth
Japanese jack mackerelOP
so whenever i redirect to /auth or any route without the prefix i can see this error


Unable to find next-intl locale because the middleware didn't run on this request. See https://next-intl-docs.vercel.app/docs/routing/middleware#unable-to-find-locale. The notFound() function will be called as a result.
am so sorry am really new to this job and dont have much experiance
@Japanese jack mackerel solved?