Creating New Users Using Ionic + Firebase 3 + Angularfire2

I have a particular use case I need to satisfy. Can someone let me know if this can be easily achieved using Ionic 2 and Firebase 3?

Use Case: User logs in and is verified as a “Paid Subscriber”. Paid subscribers can build a team of email/password based app users. Team members can later log in and access limited functions of the app based on the role they were assigned.

Using Angularfire2, I was able to actually complete this use case, but with one unintended consequence.

Problem: When the Paid Subscriber creates a new Team Member (user) the Paid Subscriber is logged out, and the newly created user becomes the authorized user of the app.

After much research I discovered that this is actually the intended result when creating new users with Firebase 3 + AngularFire2.

After some research, there are two options:

  1. Use the firebase-admin SDK to create an “admin version” of the app to create users. I can’t do this because there is not a version of the SDK (node.js and Java currently) I can use, and also because the the “admin” capability I’m trying to use needs to happen from a single app.
  2. Create a second auth reference and use that auth to create new users. I currently can’t get this workaround to work within Ionic 2 + Angularfire2

Relevant link:
firebase-kicks-out-current-user

I’m at an impasse at the moment.

Question: Given the details above, is there any way to keep the current stack, and still satisfy the use case? Is there another approach or method I can use to create new users?

Thanks for reading!

1 Like

Wouldn’t it be best to set up an invite system? I think the problem lies in trying to create a user on the fly, authentication is required. Is there a reason to create the user as opposed to sending an invite? You could also look into issuing a one-time-password.

These links might be helpful:


https://firebase.google.com/docs/auth/custom-email-handler
https://sendotp.msg91.com/

1 Like

Thanks! Yes, invites will definitely be implemented. I was going to eventually get to that, but I needed a way for “Team Members” to be added beforehand per the customer. The reasoning behind this is that the Team Leader can’t wait for a possible Team Member to be Authenticated and attached to the Team. In some cases, he’d need to build an entire team out, assign possible team members to a project tasks, and at a future date those members would create an account, login and see the projects they assigned to immediately.

I was able to work around it a bit by generating custom tokens for each team and keeping “Possible” team members in in an escrow new_members object. Based on some entered information, the app would recognize the new user, the team he belongs to and then build his team status accordingly. It’s working well for now.

@scottmotion : Do you have experience with Firebase’s invite system? Is there a way to package this “info in escrow” and send it with the invite. That way, when the user signs up it will do what my work around is doing?

Hi
I have the same problem and there doesn’t seem to be any solution except to change databases. I have been developing web apps for 25 years and have never heard of an action that allows an authenticated user create a new user and makes that newly created user the currently authenticated user…idiocracy.

Have been following all the strands to try and work out a solution especially for Angular2 and Ionic but there is nothing…so do I spend a few more days on “work arounds” or find something that just works.

Very disappointed in Firebase for not providing these action. Seems it just wants to address the simple blog/shopping site that demand you ‘leave your email address here’ before you leave. It’s not serious…oh well on to MongoDB…there’s a heap of platforms out there and life is too short. Best of luck with your solution!!

Have you tried Cloud Functions for Firebase?

When I need to get this functionality going, I just add the new user’s data (email, name, etc) to the database, and have a database listener in Cloud Functions that creates the new user, the profile node in the database, sends a welcome email, etc.

Is this in your new book? I’d love a variety of working examples of cloud functions.

Yeah…I have to agree with you…after looking around, I found the functionality from Firebase is too good to give up…so I used your method to re-instantiate the logged in user after creating a new one…works fine.

1 Like

There are a couple apps that use CF in the book, for creating user accounts like this and for push notifications.

1 Like

Thanks for the suggestion! I read a while back that I should look into Cloud Function for Firebase (I’d written it down in my notes, actually) but never got around to looking into it. Maybe it was you who mentioned it.

Would this negate the need to create new users from within the application? Does it require additional server setup/administration?

Is there a starter or example out there I could look into?

I’ve put off this project long enough because of this hang up…

Mind sharing your solution? I’m new to using cloud functions.

Cloud Functions docs are pretty awesome, I wrote a post about the specific use case of creating the user profile in the database after user creation a while ago: https://javebratt.com/firebase-cloud-functions-profile/

But for creating new users you can use this process:

  1. Have the “admin” user create a node in the database with the new user’s information, like email, name, etc.
  2. Have an onWrite() trigger for Cloud Functions that listens to new users added to that node.
  3. Use the firebase admin SDK inside that function to create a new user.
  4. Have a third party app like Mandrill or MailGun send an email to the user as welcome/onboarding.
1 Like