nuxt-auth icon indicating copy to clipboard operation
nuxt-auth copied to clipboard

proposal: Add `onRedirect` hook (for supporting `nuxt-i18n` routing)

Open kevindaizj opened this issue 1 year ago • 10 comments

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

kevindaizj avatar Mar 31 '24 02:03 kevindaizj

Totally agree with you, it's a necessary feature

mario27 avatar Apr 11 '24 00:04 mario27

this is much needed

skmd87 avatar May 14 '24 12:05 skmd87

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 😊)

zoey-kaiser avatar Jun 27 '24 08:06 zoey-kaiser

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.

mrleblanc101 avatar Sep 25 '24 19:09 mrleblanc101

Ah, I guess not. We don't just need to translate the guarded routes, but also the routes passed to the provider.

mrleblanc101 avatar Sep 25 '24 19:09 mrleblanc101

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 avatar Sep 27 '24 07:09 zoey-kaiser

@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.

mrleblanc101 avatar Oct 03 '24 21:10 mrleblanc101

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

mrleblanc101 avatar Oct 03 '24 22:10 mrleblanc101