Skip to content

Commit

Permalink
Do not add nil objects
Browse files Browse the repository at this point in the history
  • Loading branch information
jpalumickas committed Sep 24, 2020
1 parent 7e436e0 commit bd6459e
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
8 changes: 4 additions & 4 deletions AppleLogin.m
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,10 @@ - (void)authorizationController:(ASAuthorizationController *)controller didCompl

NSPersonNameComponents *fullName = appleIDCredential.fullName;
NSDictionary *userDetails = @{
@"firstName": fullName.givenName ?: nil,
@"middleName": fullName.middleName ?: nil,
@"lastName": fullName.familyName ?: nil,
@"email" : appleIDCredential.email,
@"firstName": fullName.givenName ?: @"",
@"middleName": fullName.middleName ?: @"",
@"lastName": fullName.familyName ?: @"",
@"email" : appleIDCredential.email ?: @"",
@"idToken" : idToken,
};

Expand Down
8 changes: 5 additions & 3 deletions main.mm
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,11 @@

for (NSString* key in result) {
NSString *value = result[key];
std::string napiKey = std::string([key UTF8String]);
Napi::Value napiValue = Napi::Value::From(env, [[NSString stringWithFormat:@"%@", value] UTF8String]);
obj.Set(napiKey, napiValue);
if(value != nil && [value length] > 0) {
std::string napiKey = std::string([key UTF8String]);
Napi::Value napiValue = Napi::Value::From(env, [[NSString stringWithFormat:@"%@", value] UTF8String]);
obj.Set(napiKey, napiValue);
}
}

deferred.Resolve(obj);
Expand Down

0 comments on commit bd6459e

Please sign in to comment.