Firebase logs out current user when creating a new one

强颜欢笑 提交于 2019-12-11 04:56:03

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!