How to Link Multiple Social Accounts to a Single User in Django Allauth with a Custom User and Company Model?

I'm working on a Django project where I want to authenticate users using multiple social accounts and link them to a single account in my custom models. I'm using django-allauth for social authentication, and I have a custom User model along with a Company model. The Company model has a ForeignKey to the User model.

The goal: I want a user to be able to log in using multiple social accounts (e.g., Google, Facebook) but all these accounts should link to the same user in my Company model. Essentially, the user should be able to authenticate through different providers but still map to a single User account in my system.

My setup: Django version: 4.x django-allauth version: 0.44.x I have a custom User model. Company model has a ForeignKey to the User model.

What I need help with:

  1. How do I configure django-allauth to allow a single user to authenticate via multiple social accounts and link them to the same User record?

  2. How can I ensure that all authenticated social accounts point to the same user, while still linking them to the Company model?

3)Are there any specific settings in django-allauth or middleware changes needed to make this work? I’ve already set up basic social authentication using django-allauth, but when a user tries to log in using another social account, it creates a new user instead of linking to the existing user.

I have basic social authentication working as per the django-allauth documentation, but the multiple account linking part isn’t working as expected. Any advice or examples would be greatly appreciated!

Back to Top