Setting a Firebase User photoURL value to null

Viewed 119

I have a Firebase user with a photoURL value set.

The Firebase docs say the photoURL property has a 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?

1 Answers

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.

Related