Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you tell if a user is "anonymous" in the onCreate firebase cloud function?

Inside my onCreate auth cloud function for firebase handler, how can I tell if the user is anonymous, e.g. the isAnonymous property I get on the client in the onAuthStateChanged or onIdTokenChanged response?

exports.createHandler = functions.auth.user().onCreate((user, context) => {
  let uid = user.uid,
      isAnonymous = ????;
});
like image 216
Mike Avatar asked Mar 17 '19 12:03

Mike


Video Answer


1 Answers

It seems that you cannot obtain this information from the Admin SDK. There is no method in the SDK which allows to get it.

The reason is that "isAnonymous is only a client side construct" as explained here: https://github.com/firebase/firebase-admin-node/issues/127.

isAnonymous is only a client side construct. If a user is created with signInAnonymously(), this flag is set to true (client side only). For example you can use createUser and just create a user without any profile info (no email, phone, password, etc). Would that be considered anonymous? How about if you create a user with just an email? What about a custom auth user? You could also unlink all providers from a non-anonymous account. Would that user become anonymous?

Basically, you need to apply your own criteria of what an anonymous user constitutes. When you listUsers you can perhaps check that no providers are linked and no email/phoneNumber is set on the user, etc.

like image 108
Renaud Tarnec Avatar answered Sep 28 '22 07:09

Renaud Tarnec