-
-
Notifications
You must be signed in to change notification settings - Fork 518
Description
Describe the feature
First of all what I want to achieve:
I'm using Nuxt Auth Utils and signing in successfully I want to redirect the user by keeping the current locale. So if the user signed in from /fr/sign-in they should be redirected to /fr/ and not / ( english )
Based on this example code
~/server/routes/auth/github.get.ts
export default defineOAuthGitHubEventHandler({
config: {},
async onSuccess(event, { user, tokens }) {
// set user session
return sendRedirect(event, '/') // with locale
},
onError(event, error) {
return sendRedirect(event, '/') // with locale
},
})I don't have access to the current selected browser locale. Even better would be to have the useLocalePath composable to have something like sendRedirect(event, localePath('/')).
It is possible to create an experimental custom locale detector ( https://i18n.nuxtjs.org/docs/guide/server-side-translations ) but AFAIK this only returns a translations function of type TranslationFunction<{}, DefineLocaleMessage, never>. So this code is invalid
const { t, locale, localePath } = await useTranslation(event);I found this question
https://www.answeroverflow.com/m/1357209031042924555
but AFAIK this code is not correct. I don't have access to the useI18n composable server-side. Maybe the module is just unknown but it isn't auto-imported and I can't manually import it from the module.
So for my usecase I don't need server-side translations but I need any solution to enhance my redirect routes with the current locale.
Additional information
- Would you be willing to help implement this feature?
- Could this feature be implemented as a module?
Final checks
- Read the contribution guide (The contribution guideline of nuxt-modules/i18n is compliant with Nuxt too).
- Check existing discussions and issues.