firebase-admin-node icon indicating copy to clipboard operation
firebase-admin-node copied to clipboard

linking/unlinking providers with firebase-admin js sdk not working

Open michaelpomogajko opened this issue 2 years ago • 9 comments

[REQUIRED] Step 2: Describe your environment

  • Operating System version: macOS 12.6
  • Firebase SDK version: 11.5.0
  • Firebase Product: auth
  • Node.js version: 16.17.1
  • NPM version: 9.4.0

[REQUIRED] Step 3: Describe the problem

Steps to reproduce:

I'm trying to link the email provider to a user. Code runs without issues, but applies no changes. Unlinking also not working.

Relevant Code:

Scenario: user is linked to apple and google providers, aim is to unlink those and add email provider instead.

import * as admin from 'firebase-admin';
process.env['GOOGLE_APPLICATION_CREDENTIALS'] = './firebase_token.json';

admin.initializeApp();
const auth = admin.auth();

const userId = '<userId>';
const email = '<email>';

auth.updateUser(userId, {
  providersToUnlink: ['apple.com, google.com'],
  providerToLink: {
    providerId: 'email',
    email,
  },
})

Script exits without issues, changes not applied. User still has apple and google provider but no email provider.

michaelpomogajko avatar Mar 03 '23 17:03 michaelpomogajko

Hey @pragatimodi @Xiaoshouzi-gh do you know if we have any known issues with the providersToUnlink() API? Thank you!

lahirumaramba avatar Mar 03 '23 17:03 lahirumaramba

Hi, any update on this?

michaelpomogajko avatar Mar 13 '23 12:03 michaelpomogajko

Upon initial inspection, it appears that the providersToUnlink field should be set to ['apple.com', 'google.com'] rather than ['apple.com, google.com']. Additionally, for email provider, the value should be updated to uid instead of email. Enclosed please find the updated payload:

{
  providersToUnlink: ['apple.com', 'google.com'],
  providerToLink: {
    providerId: 'email',
    uid: email,
  }

Please inform me if this resolves your concern.

Xiaoshouzi-gh avatar Mar 13 '23 18:03 Xiaoshouzi-gh

Hi @Xiaoshouzi-gh,

thanks for the hint. Silly typo in the providersToUnlink field. I am able to unlink the providers since you've pointed that out.

Nonetheless, the linking is still not working after using the email as the uid for the provider, unfortunately

michaelpomogajko avatar Mar 13 '23 19:03 michaelpomogajko

I'm experiencing this issue as well with twitter.com

wolfy-nft avatar Mar 30 '23 06:03 wolfy-nft

Any updates here? Still can't link email provider with firebase-admin

michaelpomogajko avatar Oct 18 '23 15:10 michaelpomogajko

Hi Michael, thanks for reaching out. After digging through the code and Identity Platform API reference, it seems we do not support email/password as a provider (correction - providerId is 'password') to link using the providerToLink field.

However, you can still call the same API to update the email and password.

Your payload should look like this

auth.updateUser(userId, {
  email,
  password
  providersToUnlink: ['apple.com', 'google.com'],
})

Please see identity platform API reference with more detail.

Xiaoshouzi-gh avatar Oct 18 '23 17:10 Xiaoshouzi-gh

Hi @Xiaoshouzi-gh, thanks for your swift response. In my case, I don't try to link email/password, but only email with magic link. The documentation you provided doesn't mention this.

If it turns out this also doesn't work, then I kindly suggest to update the sdk to throw an error when trying to do so. The current behaviour implies that it's supported

michaelpomogajko avatar Oct 19 '23 09:10 michaelpomogajko