简体   繁体   中英

Setting a Firebase User photoURL value to null

I have a Firebase user with a photoURL value set.

The Firebase docs say the photoURL property has a string | null string | null value.

Now I want to remove the photoURL, so I thought I could set it to null using the Web v9 modular SDK .

But this does not work:

updateProfile(auth.currentUser, { photoURL: null });

However this does work:

updateProfile(auth.currentUser, { photoURL: '' });

If I use an empty string Firebase will convert it to null afterwards. But I can't directly set it to null .

Is this a feature or a bug?

I am now keeping a user doc in Firestore, and I keep the Firebase Auth profile in sync using a Firebase Cloud Function. Using the Cloud Function onUpdate trigger it will run anytime the Firestore user doc changes.

So whenever the Firestore user doc updates I have some code that automatically updates the Firebase Auth profile, the relevant part for the photoURL looks like this:

const dataAfterChange = change.after.data();
await admin.auth().updateUser(userId, {
  photoURL: dataAfterChange.photoUrl,
});

I do this for convenience, because I only have to worry about updating the Firestore user doc and everything else will automatically be kept in sync.

It also has the strange benefit that I can set photoURL directly to null .

But I'm not sure why this works exactly. Perhaps admin.auth().updateUser() inside the Cloud Function works differently than the updateProfile() of the web SDK.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM