Skip to content

Commit

Permalink
fix: Support clearing user with null on iOS native bridge (#207)
Browse files Browse the repository at this point in the history
Cordova passes the values as NSNull and not nil like on React Native.

Fixes #203
  • Loading branch information
jennmueng committed Mar 18, 2021
1 parent d2d2ab0 commit 5790b84
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
- build(ios): Bump `sentry-cocoa` to 6.2.1 (#205)
- feat(android): Add Android native bridge, full scope sync, and cached events (#202)
- feat: Set `event.origin` and `event.environment` tags (#204)
- fix: Support clearing user with null on iOS native bridge (#207)
- fix(ios): Handle auto session tracking start on iOS (#206)

## v1.0.0-rc.0
Expand Down
10 changes: 7 additions & 3 deletions src/ios/SentryCordova.m
Original file line number Diff line number Diff line change
Expand Up @@ -197,19 +197,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 5790b84

Please sign in to comment.