Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Support clearing user with null on iOS native bridge #207

Merged
merged 3 commits into from
Mar 18, 2021
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)

## 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 @@ -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