Magesh Ravi

Magesh Ravi

Artist | Techie | Entrepreneur

Django-allauth: Resolving conflicts between local and social accounts

I'm working on a project that uses Django-allauth. The application accepts signing up with email (local account) and signing in with Google (social account).

Imagine a user signing up with their email (local account). Later, the same user tries to sign in with Google with the same email. What's the expected behaviour here?

  1. Create a new social account. Treat this account differently from the local account.
  2. Do NOT create a new social account. Just use the email from the social account provider to authenticate and log in as the local account user.

If the latter option is your preferred implementation, the following settings should help.

ACCOUNT_AUTHENTICATION_METHOD = "email"
ACCOUNT_EMAIL_REQUIRED = True

SOCIALACCOUNT_PROVIDERS = {
  "google": {
      "EMAIL_AUTHENTICATION": True,
      "SOCIALACCOUNT_EMAIL_AUTHENTICATION_AUTO_CONNECT": True
  }
}

Last updated: June 20, 2024, 1:12 p.m.