Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NextAuth: Multiple users for one account

I was wondering if there was any way to have multiple users for one account provider. In this case, have a session which has a field to precise the active user (the one on which you're logged) and be able to switch easily between users with a menu.

Someone has any resource to achieve that or even if it's possible natively ?

Have a nice day !

like image 642
OnlyMyPlays Avatar asked Mar 21 '26 15:03

OnlyMyPlays


1 Answers

Quick answer, no, there are no built-in features specified in the next-auth documentation that do multiple users for one account.

However, the sky is the limit and this would be a really cool feature for you to implement and not so difficult. The real beauty of next-auth is to be the foundation for these kinds of cool features, not to be a full service like Firebase.

I suppose that what you are trying to accomplish is something like Netflix where you have 1 account and inside you can create 'sub-users'.

What would be a good solution for this problem is what you are describing. You have a specific field that points to a list of sub-users for that account. You then can CRUD (Create, Read, Update and Delete) sub-users easily by modifying that list.

E.g. You could use a database adapter, for example MongoDB, where you would add a new field, a list of sub-users IDs. Then you could ask the user which sub-user to use. After you get the ID it is exactly like a normal user, you query by ID and get the sub-user data.

like image 195
Am4teur Avatar answered Mar 23 '26 06:03

Am4teur



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!