Next.js Discord

Discord Forum

next-intl based on user settings

Unanswered
California pilchard posted this in #help-forum
Open in Discord
California pilchardOP
I have a quick question. Im using next-intl for i18n . Its working well, but I wanna be able if user is authentificated , to erase locale by the language from user settings. Im using supabase for backend. In getRequestConfig this make the job :
export default getRequestConfig(async ({locale}) => {
  // Validate that the incoming `locale` parameter is valid
  if (!routing.locales.includes(locale as any)) notFound();
  const supabase = createServerClient();
  const { data: { user } } = await supabase.auth.getUser();
  if (user) {
    const { data: user_data, error } = await supabase
      .from('user')
      .select('language')
      .eq('id', user.id)
      .single();
    if (!error && user_data)
      locale = user_data.language;
  }
  return {
      locale: locale,
    messages: (await import(`../../messages/${locale}.json`)).default
  };
});

But I have this warning in console :
You've read the `locale` param that was passed to `getRequestConfig` but have also returned one from the function. This is likely an error, please ensure that you're consistently using a setup with or without i18n routing: https://next-intl-docs.vercel.app/docs/getting-started/app-router

So I guess isnt a good way to do it, maybe in middleware but I have no idea how to get the locale if sometime im using localePrefix as never

Thx a lot !

2 Replies

California pilchardOP
any idea ?
How to get access to the locale from middleware with localePrefix to never ?