sidebase / nuxt-auth

Authentication built for Nuxt 3! Easily add authentication via OAuth providers, credentials or Email Magic URLs!
https://auth.sidebase.io
MIT License
1.31k stars 164 forks source link

Immediate redirect to Provider signIn #721

Open r4id4h opened 7 months ago

r4id4h commented 7 months ago

Describe the feature

We're aiming to implement a unified authentication experience across our two Nuxt applications, which are hosted on separate subdomains. The primary application is available at example.com, while the secondary application resides at app.example.com. Additionally, our Keycloak authentication server is hosted on auth.example.com. The goal is to facilitate a smooth user journey where a user can log in once at example.com, and then navigate to app.example.com via a button click, all while remaining authenticated.

Currently I can login at example.com then redirect to app.example.com (with globalAppMiddleware activated). I will then get the nuxt-auth Sign In page where I can click the button "Sign In with Keycloak" and I'm logged in since all the cookies and request headers are set correctly. Would it be possible to add a configuration to skip the signIn page and immediately redirect to the keycloak login?

Maybe I'm overseeing something and it's already possible to achieve this but I couldn't find anything about it.

How would you implement this?

No response

Additional information

Provider

r4id4h commented 7 months ago

Nevermind, I achieved the wanted behaviour by just intercepting while bootstrapping and calling useAuth.signIn

dhondtlaurens commented 4 months ago

I am unsure why this issue was closed, as it seems the behavior is not aligning with the documentation provided here. According to the documentation, setting the defaultProvider should redirect unauthorised users directly to the provider’s sign-in page instead of displaying the app-login page.

dhondtlaurens commented 4 months ago

Additionally, I wanted to note that this behaviour worked as expected in version 0.7.2, but there seems to be a regression in version 0.8.0.

zoey-kaiser commented 3 months ago

Hi @dhondtlaurens 👋

I just tried to reproduce the error you outlined above and could not reproduce the issue. Here is the link to my test playground for this issue: https://github.com/zoey-kaiser/nuxt-auth-starters/tree/721/test-default-provider/starters/authjs-github

I set defaultProvider to github and when I navigated to a protected page, I was redirected to the Github OAuth connection page. (r1).

Would you be so kind to create a reproduction of this error? You are welcome to clone the repository I linked above and attempt to reproduce the issue 😊

R1: https://github.com/user-attachments/assets/f5aae2fd-ea5c-4aa5-a63f-c213962cc225

dhondtlaurens commented 3 months ago

Hi @zoey-kaiser 👋

I’ve successfully reproduced the issue. You can find the forked repository I used for testing at this link: https://github.com/dhondtlaurens/nuxt-auth-starters-issue-721.

In my setup, I configured the defaultProvider to github in nuxt.config.ts and disabled the custom sign-in page in [...].ts. With globalAppMiddleware enabled, unauthenticated users are redirected to the GitHub OAuth page when clicking on the Secured Page link. However, if navigating directly to http://localhost:3000/secure, the app-login page is displayed instead. (R1)

Additionally, I encountered the following error when navigating directly to the secured page:

[nuxt] [request error] [unhandled] [500] The first argument must be of type string or an instance of Buffer, ArrayBuffer Array, or an Array-like Object. Received an instance of URLSearchParams

Please let me know if you need any more details or if there’s anything else I can assist with!

R1: https://github.com/user-attachments/assets/9a6104d8-05c1-42b1-b1f2-88fab50d4456

zoey-kaiser commented 3 months ago

Hi @dhondtlaurens 👋

Thanks for the fantastic reproduction! The only difference between our setups is that I did not remove the custom login page! I'll test out removing that from my app, too; otherwise, I work based on your reproduction!

Ill also look into the behavior differences between navigating to a page vs. opening it directly via a link!

Ill have some time tomorrow and keep you updated on the progress!

gabrielws commented 3 months ago

Hi, any progress? I'm implementing IBM Verify and I wanted it to be redirected directly to the provider, and I'm also getting the error mentioned above:

ERROR  [nuxt] [request error] [unhandled] [500] The first argument must be of type string or an instance of Buffer, ArrayBuffer, or Array or an Array-like Object. Received an instance of URLSearchParams

image

dhondtlaurens commented 2 months ago

Hi @zoey-kaiser

Thank you for your continued support with this issue. I wanted to check in to see if there have been any updates since I provided the reproduction. If there are any plans to address this, I’d be happy to assist further in identifying the issue or working on a fix. I appreciate all the effort you’re putting into resolving this.

Looking forward to your feedback.

Best regards, Laurens D’Hondt

zoey-kaiser commented 2 months ago

Hi @dhondtlaurens 👋

I have this issue on my TODO for the next steps after the last 0.9.0 release! I was sadly still pretty busy with the changes for that release and deprioritized this, as it needs a small investigation! Ill keep you posted 😊