atinux / nuxt-auth-utils

Add Authentication to Nuxt applications with secured & sealed cookies sessions.
MIT License
973 stars 91 forks source link

Question: How to handle multiple account connections in OAuth Authentication? #286

Closed HugoRCD closed 16 hours ago

HugoRCD commented 1 week ago

If a user has already signed in to my application and accepted the OAuth authorization, how should I handle the situation if they have multiple accounts and wish to connect with a different one?

atinux commented 6 days ago

In the onSuccess callback of the OAuth provider, you can check if the user is already authenticated using the getUserSession(event) if this is the case, you can "link" the account in your database then.

You may want to add a security layer for example if they don't match the same email for example (not required of course).

HugoRCD commented 6 days ago

Reference in new issue

I'm sorry, I don't know if I've misunderstood your answer or if I've explained my question incorrectly, but I'm talking about the case where a user with several Google or Github accounts, for example, who has accepted the oauth window, disconnects and wants to use another of his Google accounts. Is this case manageable?

atinux commented 6 days ago

If the user logout and click on the Google login again, it will be redirect to Google page to select an account, that's it.

See the example with https://draw.nuxt.dev (see source code):

https://github.com/user-attachments/assets/ee00f5a6-938f-4d42-bc1a-4878c15e7307

HugoRCD commented 16 hours ago

I'm really sorry, I realized that it was simply because I only had one Google account on my machine, but yes indeed, with several it works like a charm!