1
votes

I'm creating an iPhone app where an admin user can create new users, but as the Firebase documentation states "If the new account was created, the user is signed in automatically", so I'm looking for a way to avoid signing in to that newly created user.

Is there any way I can avoid this without using the new Firebase Admin SDK (that is web only AFAIK)?

2
The Firebase Admin SDK is for running on a node.js server (that doesn't mean it is just for web). But if you want a client-side only approach, it indeed won't work. You might be able to try something similar to this: stackoverflow.com/questions/37517208/…Frank van Puffelen

2 Answers

2
votes

You can solve this in multiple ways:

Option 1 : save the credentials of the admin user securely on your device. Then, when the user creates a new user, log in with the admin credentials. This will log you out and immediately log you back in.

Option 2 : use the admin sdk to create a user with a rest API call on the web side.

0
votes

I got this Javascript smart workaround working for iOS. Works flawlessly:

NSString *plistPath = [[NSBundle mainBundle] pathForResource:@"GoogleService-Info" ofType:@"plist"];
FIROptions *secondaryAppOptions = [[FIROptions alloc] initWithContentsOfFile:plistPath];
[FIRApp configureWithName:@"Secondary" options:secondaryAppOptions];
FIRApp *secondaryApp = [FIRApp appNamed:@"Secondary"];
FIRAuth *secondaryAppAuth = [FIRAuth authWithApp:secondaryApp];

[secondaryAppAuth createUserWithEmail:user.email
                             password:user.password
                           completion:^(FIRUser * _Nullable user, NSError * _Nullable error) {
                                [secondaryAppAuth signOut:nil];
                          }];