Skip to content

Commit 5e67d3e

Browse files
Update ios implementation
1 parent 8008337 commit 5e67d3e

1 file changed

Lines changed: 32 additions & 9 deletions

File tree

src/ios/FirebaseUIAuthPlugin.m

Lines changed: 32 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ - (void)getToken:(CDVInvokedUrlCommand *)command {
119119
} else {
120120
CDVPluginResult *pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsString:@"no_user_found"];
121121

122-
[self.commandDelegate sendPluginResult:pluginResult callbackId:self.signInCallbackId];
122+
[self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
123123
}
124124
}
125125
@catch (NSException *exception) {
@@ -135,18 +135,18 @@ - (void)getCurrentUser:(CDVInvokedUrlCommand *)command {
135135

136136
if (user != nil) {
137137

138-
CDVPluginResult *pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString:[self formatUser:user]];
138+
CDVPluginResult *pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsDictionary:[self formatUser:user]];
139139

140140
[self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
141141

142142
} else {
143-
CDVPluginResult *pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK];
143+
CDVPluginResult *pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsDictionary:[self formatEmptyUser]];
144144

145-
[self.commandDelegate sendPluginResult:pluginResult callbackId:self.signInCallbackId];
145+
[self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
146146
}
147147
}
148148
@catch (NSException *exception) {
149-
NSLog(@"getToken error %@", [exception reason]);
149+
NSLog(@"getCurrentUser error %@", [exception reason]);
150150
@throw exception;
151151
}
152152
}
@@ -254,6 +254,9 @@ - (BOOL)application:(UIApplication *)app
254254
- (void)signOut:(CDVInvokedUrlCommand *)command {
255255

256256
@try {
257+
258+
self.signInCallbackId = command.callbackId;
259+
257260
if ([self.authUI signOutWithError:nil]) {
258261
[self raiseEvent:@"signoutsuccess" withData:nil];
259262
[self signInAnonymous];
@@ -271,6 +274,8 @@ - (void)deleteUser:(CDVInvokedUrlCommand *)command {
271274

272275
@try {
273276

277+
self.signInCallbackId = command.callbackId;
278+
274279
FIRUser *user = [[FIRAuth auth] currentUser];
275280

276281
[user deleteWithCompletion:^(NSError * _Nullable error) {
@@ -298,6 +303,8 @@ - (void)sendEmailVerification:(CDVInvokedUrlCommand *)command {
298303

299304
@try {
300305

306+
self.signInCallbackId = command.callbackId;
307+
301308
FIRUser *user = [[FIRAuth auth] currentUser];
302309

303310
[user sendEmailVerificationWithCompletion:^(NSError * _Nullable error) {
@@ -319,6 +326,8 @@ - (void)reloadUser:(CDVInvokedUrlCommand *)command {
319326

320327
@try {
321328

329+
self.signInCallbackId = command.callbackId;
330+
322331
FIRUser *user = [[FIRAuth auth] currentUser];
323332

324333
[user reloadWithCompletion:^(NSError * _Nullable error) {
@@ -347,20 +356,20 @@ - (NSDictionary *)formatUser:(FIRUser *)user {
347356
NSNumber *isEmailVerified;
348357

349358
NSNumber *newUser;
350-
359+
351360
self.anonymous = false;
352-
361+
353362
if ([user isEmailVerified]) {
354363
isEmailVerified = @YES;
355364
} else {
356365
isEmailVerified = @NO;
357366
}
358367

359368
FIRUserMetadata *metadata = [user metadata];
360-
369+
361370
NSDate *lastSignInDate = [metadata lastSignInDate];
362371
NSDate *creationDate = [metadata creationDate];
363-
372+
364373
if ([lastSignInDate compare:creationDate] == NSOrderedSame) {
365374
newUser = @YES;
366375
} else {
@@ -387,6 +396,20 @@ - (NSDictionary *)formatUser:(FIRUser *)user {
387396
return result;
388397
}
389398

399+
- (NSDictionary *)formatEmptyUser {
400+
401+
NSDictionary *result;
402+
403+
result = @{@"email" : (id)[NSNull null],
404+
@"emailVerified" : @NO,
405+
@"name" : (id)[NSNull null],
406+
@"id" : (id)[NSNull null],
407+
@"newUser" : @NO
408+
};
409+
410+
return result;
411+
}
412+
390413
- (NSString *)emptyIfNull:(NSString *)value {
391414
if (value == nil) {
392415
return (id)[NSNull null];

0 commit comments

Comments
 (0)