简体   繁体   中英

How to set custom User UID for Firebase Authentication users?

I want to store a custom ID as User UID in Firebase Authentication. Can you do that? Based on my searches it seems I would need to use Firebase Realtime Database to store this extra ID, but I want to avoid another product and just have everything in Firebase Authentication (I just need to store this 3rd party ID somewhere).

在此处输入图片说明

My use case is as follows:

  1. User registers with email/password OR Google Sign-in (using Firebase Authentication)

    mAuth.createUserWithEmailAndPassword(email, password) mAuth.signInWithCredential(credential) // or Google Sign-In, cretaes a new account if not existing

  2. User enters phone number and verifies it (using firebase Authentication)

  3. If all good, automatically the user is registered with our 3rd party partner's backend server, which sends back user's UID (they generate it and I have to store it). It looks like 77a644e1-9322-4291-854e-5dabb59cc296b .

  4. I want to store this generated user ID to Firebase Authentication user.

Firebase Authentication was not designed to store general per-user information. Databases are better at that.

The only way to store arbitrary data per user is in the form of custom claims . Custom claims are primarily used to store small bits of data to be used in security rules for the purpose of authorizing access to data in Realtime Database, Firestore, and Cloud Storage by way of security rules . But if you really want to store this extra string in custom claims, you could. But I would use a database instead.

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