Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The email address is already in use by another account #120

Closed
bitlab-code opened this issue Oct 25, 2017 · 3 comments
Closed

The email address is already in use by another account #120

bitlab-code opened this issue Oct 25, 2017 · 3 comments

Comments

@bitlab-code
Copy link

bitlab-code commented Oct 25, 2017

I report an issue opened on firebase-functions becouse it seem an firebase-admin issue
(issue)

[REQUIRED] Step 2: Describe your environment

  • Operating System version: MacOS Sierra
  • Firebase SDK version: ^5.2.1
  • Library version: _____
  • Firebase Product: auth

[REQUIRED] Step 3: Describe the problem

I'm trying to insert two user with same email address but with different phone number.
When configure sign-in methods I setup only phone number as authentication provider (Email/password disabled) and I allowed multiple accounts with the same email address.

Steps to reproduce:

The snipped code of the function (onWrite) trigger from location /USERS in the Database:

    const auth = admin.auth();
    /* ... */
    if (!event.data.previous.exists()) {
      const userData = event.data.current.val();
      console.log(`A new user was created: ${uid}. Now syncing in Auth...`, userData);
      return auth.createUser({
        uid: uid,
        email: userData.email,
        phoneNumber: userData.phone,
        disabled: false
      }).then(userRecord => {
        console.log(`Done. Created new user in Auth: ${uid}`, userRecord);
        return Promise.resolve(uid);
      }).catch(error => {
        console.error(`Error Creating new user in Auth: ${uid}`, error);
        sendEmail.logEmail(/* ... */);
        return Promise.reject(`${error}`);
      });
    } 

All ok when I enter the first user. The error occurs on the second (with the same email)

Relevant Code:

the log

Error Creating new user in Auth: -Ku_GnJvedvEbtfgn0xP { Error: The email address is already in use by another account.
    at FirebaseAuthError.Error (native)
    at FirebaseAuthError.FirebaseError [as constructor] (/user_code/node_modules/firebase-admin/lib/utils/error.js:39:28)
    at new FirebaseAuthError (/user_code/node_modules/firebase-admin/lib/utils/error.js:104:23)
    at Function.FirebaseAuthError.fromServerError (/user_code/node_modules/firebase-admin/lib/utils/error.js:128:16)
    at /user_code/node_modules/firebase-admin/lib/auth/auth-api-request.js:399:45
    at process._tickDomainCallback (internal/process/next_tick.js:135:7)
  errorInfo: 
   { code: 'auth/email-already-exists',
     message: 'The email address is already in use by another account.' } }
@google-oss-bot
Copy link

Hmmm this issue does not seem to follow the issue template. Make sure you provide all the required information.

@bojeil-google
Copy link
Contributor

Hey @bitlab-code, this works as expected. The "multiple accounts with the same email address" applies to different providers. You can have multiple users with different providers but the provider on one has the same email as another provider on another user. So you can have a email/password user, another Google user with the same email and each user will have different uid as expected. However, you can't have 2 users with the same top level email which is also used to identify the email used for password accounts. Think of it, how can you have 2 email/password users with the same email? The top level email must always be unique regardless of setting or whether there is no password on the account. This also makes lookup of accounts by email always return at most one result.

@bitlab-code
Copy link
Author

Ok @bojeil-google many thanks for the explanation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants