Support i18n redirect routes #1538
Replies: 7 comments 3 replies
-
Hi there, you can use a plugin like that :
this way you can override the default behavior of redirections. Don't forget to reference your plugin like that :
Good luck ! |
Beta Was this translation helpful? Give feedback.
-
@Tcharlyson if a user gets on your page, the locale is stored in the cookie like this plugin does not support a |
Beta Was this translation helpful? Give feedback.
-
Couldn't you simply do the following? export default ({ app, $auth }) => {
$auth.onRedirect((to) => {
return app.localePath(to)
})
} With this, navigating to /fr/profile will redirect to /fr/login, and vice-versa with the /en/ prefix too. |
Beta Was this translation helpful? Give feedback.
-
This will not work when using OAuth Scheme, how to send the correct redirect_uri to our OAuth provider in a i18n context. |
Beta Was this translation helpful? Give feedback.
-
Instead of using path, nuxt-auth should use route name. |
Beta Was this translation helpful? Give feedback.
-
so just that everyone is on the same page. // nuxt.config.js
export default {
// ...
i18n: {
strategy: 'prefix', // THAT IS IMPORTANT HERE !
locales: [
{ code: 'en', iso: 'en', file: 'en-US.js', fallbackFile: 'en-US.js', name: 'English', path: '/en' },
{ code: 'fr-fr', iso: 'fr-FR', file: 'fr-FR.js', fallbackFile: 'fr-FR.js', name: 'Francais', path: '/fr-fr' },
{ code: 'de-at', iso: 'de-AT', file: 'de-AT.js', fallbackFile: 'de-AT.js', name: 'Deutsch', path: '/de-at' },
],
lazy: true,
langDir: 'lang/',
defaultLocale: 'en',
},
auth: {
strategies: {
keycloak: {
scheme: '~/schemes/keycloak.js', // changes logout & fetch-user stuff
endpoints: {
// ...
},
grantType: 'authorization_code',
responseType: 'code',
scope: ['openid', 'profile', 'email'],
codeChallengeMethod: 'plain',
audience: '',
logoutRedirectURI: '/',
},
},
redirect: {
login: '/login', // issue with i18n-strategy
logout: '/',
callback: '/login',
home: '/profile', // issue with i18n-strategy
},
plugins: ['@/plugins/auth.js'], // that's the "redirect" plugin from docs, but it does NOT work, bc NO index page is there.
},
// ...
} |
Beta Was this translation helpful? Give feedback.
-
Have you found any solution for this? |
Beta Was this translation helpful? Give feedback.
-
My nuxt project uses i18n with the
prefix
strategy, meaning all routes include a locale like/en/login
. A default route like/login
is not generated. The problem is, the/login
page is returning a404
and if I prefix the redirect url with a default language/en/profile
the user's locale gets reset. Example: I login from/fr/login
and end up on/en/profile
although I would want the french version of this page. This is BAD!Describe the solution you'd like to see
It would be nice to provide an object like
{ route: 'login' }
and this will be resolved to the current locale. Or just use an option flag likei18nRedirects
. The result should be that the auth-module useslocalePath()
helper in the redirects. I can adapt the OAuth2 Schema for theredirectURI
and thelogoutRedirectURI
but I cannot change theredirect('home', true)
in my custom Schema, it's just too much of a hassle tbh.Describe alternatives you've considered
Providing my own custom Schema.
Beta Was this translation helpful? Give feedback.
All reactions