Reputation: 334
In my application, it should be possible to add new users by other users.
I'm having the problem that I can't just create an account - Firebase Authentication - with a random password for this new user, because it will automatically log in with this new account, using createUserWithEmailAndPassword
.
If I just create a new doc in the usercollection (with the name, birthday, ... linked to an account's id), and afterwards this user creates an account (Firebase Authentication), I will need to check every collection's docs where this usercollection's docid is used and replace it with the created uid from createUserWithEmailAndPassword
. Also not a bulletproof solution...
Any advice on how to do this?
Upvotes: 1
Views: 494
Reputation: 7566
I suggest you use the Firebase Admin Auth SDK to create a new user server-side. This means you will have to implement some server-side solution if you don't already have one. An HTTP-triggered Cloud Function would be a good option. If you're new to Cloud Functions, the samples on GitHub are a good place to start. A very basic version of your function could look like this:
exports.createUser = functions.https.onRequest(async (req, res) => {
const email = decodeURI(req.query.email);
await admin.auth().createUser({
email: email,
password: "password", // however you're planning on creating the password goes here
})
});
Your code will be more complex, but it's a starting point.
Upvotes: 2