firebase / firebase-admin-node

Firebase Admin Node.js SDK
https://firebase.google.com/docs/admin/setup
Apache License 2.0
1.62k stars 367 forks source link

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

Open michaelpomogajko opened 1 year ago

michaelpomogajko commented 1 year ago

[REQUIRED] Step 2: Describe your environment

[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.

lahirumaramba commented 1 year ago

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

michaelpomogajko commented 1 year ago

Hi, any update on this?

Xiaoshouzi-gh commented 1 year ago

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.

michaelpomogajko commented 1 year ago

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

wolfy-nft commented 1 year ago

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

michaelpomogajko commented 11 months ago

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

Xiaoshouzi-gh commented 11 months ago

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.

michaelpomogajko commented 11 months ago

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