Skip to content

Commit

Permalink
fix: Support setting user as null on iOS native bridge
Browse files Browse the repository at this point in the history
  • Loading branch information
jennmueng committed Mar 18, 2021
1 parent 8bd1235 commit 8922721
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/ios/SentryCordova.m
Original file line number Diff line number Diff line change
Expand Up @@ -182,19 +182,23 @@ - (void)setUser:(CDVInvokedUrlCommand *)command {
NSDictionary *user = [command.arguments objectAtIndex:0];
NSDictionary *otherUserKeys = [command.arguments objectAtIndex:1];

bool userIsNull = (nil == user || [user isEqual:[NSNull null]]);
bool otherUserKeysIsNull =
(nil == otherUserKeys || [otherUserKeys isEqual:[NSNull null]]);

[SentrySDK configureScope:^(SentryScope *_Nonnull scope) {
if (nil == user && nil == otherUserKeys) {
if (userIsNull && otherUserKeysIsNull) {
[scope setUser:nil];
} else {
SentryUser *userInstance = [[SentryUser alloc] init];

if (nil != user) {
if (!userIsNull) {
[userInstance setUserId:user[@"id"]];
[userInstance setEmail:user[@"email"]];
[userInstance setUsername:user[@"username"]];
}

if (nil != otherUserKeys) {
if (!otherUserKeysIsNull) {
[userInstance setData:otherUserKeys];
}

Expand Down

0 comments on commit 8922721

Please sign in to comment.