Jabal Logian
Jabal Logian

Reputation: 2332

Android create a new user in Firebase Authentication but with data from Firebase Firestore

The Story

I'm creating 2 Android applications using Java in Android Studio and Firebase as the backend.

The first app (let's call it the Doctor app means an app for doctors) has a feature of registering new users to Firebase Firestore.

The second app (let's call it the Patient app means an app for patients) has a feature of showing patient's records.

In the Doctor app, doctors can save new patient's data such as name, ID number, birth date, and gender like this picture:

Doctor app

If the doctor clicks the register button, the app would save the patient data into Firebase Firestore (but not register the patient into Firebase Authentication) with this configuration:

Firebase Firestore

The patient's ID is programmatically generated using a random string generator.

Then the patient can sign up for the app using the Patient app using email and password in Firebase Authentication like this:

Patient app

First, the patient should select his/her name from the list of users (saved by doctors) in Firebase Firestore. Then if the patient finds his/her name, the patient had to input his/her email and password. If the patient clicks the signup button, the app would create a new user to Firebase Authentication like this one:

Firebase Authentication

and store the email to Firebase Firestore like this one (add the email to selected patient name):

Firebase Firestore

The Question

What's the code for Patient app so the app could:

  1. Create a new user with an email and password in Firebase Authentication but with the user ID from Firebase Firestore?
  2. Save the email to the selected ID in Firebase Firestore?

Note: if it's impossible, I would add email and password fields to the Sign Up page in the Patient app instead.

Upvotes: 0

Views: 957

Answers (1)

Frank van Puffelen
Frank van Puffelen

Reputation: 598740

If you implement a custom identity provider you have full control over the UID that it uses.

If you want to use the built-in email+password provider, you won't have control over the UIDs it generates. The most common alternative there would be to store the custom ID you want in the user's token as a custom claim.

Upvotes: 1

Related Questions