proposal: Add `onRedirect` hook (for supporting `nuxt-i18n` routing)
Describe the feature
Implement similar functionality of Nuxt 2 nuxt-auth module: Feature
How would you implement this?
No response
Additional information
- [ ] Would you be willing to help implement this feature?
Provider
- [ ] AuthJS
- [ ] Local
- [ ] Refresh
- [ ] New Provider
Totally agree with you, it's a necessary feature
this is much needed
I really like this idea! Do you have any more context you could provide to this? Then I would look into beginning to work on this feature (unless you want to take a crack at it 😊)
Could this be achieved with a custom middleware/auth.global.ts currently while waiting for this feature to be implemented ?
I tried copy-pasting the current middleware and then modifying it, but it reference too many other functions that I couldn't find how to import once inside my app.
Ah, I guess not. We don't just need to translate the guarded routes, but also the routes passed to the provider.
Hi @mrleblanc101 👋
This feature is already supported by the authjs provider using the redirect callback. Have a look at the docs here: https://next-auth.js.org/configuration/callbacks#redirect-callback
Inside your NuxtAuthHandler you receive the url and baseUrl, can then modify the redirect URL and return the internalized URL! For the local provider, we will need to adapt the implementation, but maybe this already covers your use case!
@zoey-kaiser Thanks, but I'm not sure I understand how to make it work.
To change locale on the server-side, I need to know the user locale, I just need to get it from the cookie.
But to get the value of the i18n_redirected cookie using h3 getCookie(event, "i18n_redirected");, I need access to the h3 event from the request.
Also, if I want keycloak locale to match my application locale, I need to pass an additional param called ?ui_locale=fr.
How would I do this ?
@nuxtjs/auth-next had an additionalParams key in the signIn method second argument just for this:
https://auth.nuxtjs.org/schemes/openIDConnect#:~:text=Additional%20arguments%20can%20be%20passed%20through%20to%20the%20OpenID%20Connect%20provider%20using%20the%20params%20key%20of%20the%20second%20argument%3A