问题
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)?
回答1:
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.
回答2:
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];
}];
来源:https://stackoverflow.com/questions/41154181/firebase-logs-out-current-user-when-creating-a-new-one