Skip to content
Back

Avoiding 409 user_already_exists When Migrating Email/Password Users to OAuth in Appwrite

  • 0
  • Auth
zephyr
9 Jun, 2025, 01:40

We’ve migrated all our existing email+password users into Appwrite and now want to switch entirely to OAuth (Google & Apple) for authentication.

Our plan is that with the next app release, users will see a simple login page: Apple Sign-In on iOS, Google Sign-In on Android. We no longer want to prompt them for a password.

Migration setup:

I ran a Node.js script using account.create() to import users like my-apple-account@hotmail.com and my-google-account@gmail.com.

After migration:

**Android & Google: ** await account.createOAuth2Session(provider: OAuthProvider.google); with my-google-account@gmail.com works perfectly and links to the existing Appwrite user.

**iOS & Apple: ** await account.createOAuth2Session(provider: OAuthProvider.apple); with my-apple-account@hotmail.com also works and links correctly.

Cross-provider test: Out of curiosity, on iOS I tried signing in with Google (same my-google-account@gmail.com). The OAuth selector appeared but then redirected to: https://fra.cloud.appwrite.io/console/auth/oauth2/failure?error={"message":"A+user+with+the+same+id,+email,+or+phone+already+exists+in+this+project.","type":"user_already_exists","code":409}#

Appwrite is attempting to merge the Google identity into the Apple account (because an active session exists for the Apple user) and fails, since my-google-account@gmail.com already has its own Appwrite user.

Questions:

Is there a way to force createOAuth2Session to always link by email to the “correct” existing account, instead of trying to merge into the currently active session?

Would clearing all existing sessions or calling something like account.deleteSessions() before createOAuth2Session(...) prevent this merge attempt?

Are there any recommended migration strategies or Appwrite settings to avoid the 409 user_already_exists conflict when moving from email/password to OAuth?

Any best practices or official guidance would be much appreciated—thank you! 😊

TL;DR
Migrated email/password users to Appwrite, now transitioning to OAuth. When using multiple OAuth providers, facing 409 user_already_exists error. Seeking guidance on linking existing accounts in Appwrite. **Solution:** - Clear existing sessions or call account.deleteSessions() before createOAuth2Session(...) to prevent merge attempts. - Ensure createOAuth2Session links accounts correctly by using user's email. - Explore migration strategies or adjust Appwrite settings to avoid user_already_exists conflicts during transition from email/password to OAuth.
Reply

Reply to this thread by joining our Discord

Reply on Discord

Need support?

Join our Discord

Get community support by joining our Discord server.

Join Discord

Get premium support

Join Appwrite Pro and get email support from our team.

Learn more