Skip to content

Commit 29c6b09

Browse files
committed
Add support for all userId variations
1 parent de0a8b4 commit 29c6b09

File tree

2 files changed

+21
-12
lines changed

2 files changed

+21
-12
lines changed

android/src/main/java/io/sentry/RNSentryModule.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,8 @@ private UserBuilder getUserBuilder(ReadableMap user) {
255255
}
256256
if (user.hasKey("userID")) {
257257
userBuilder.setId(user.getString("userID"));
258+
} else if (user.hasKey("userId")) {
259+
userBuilder.setId(user.getString("userId"));
258260
} else if (user.hasKey("id")) {
259261
userBuilder.setId(user.getString("id"));
260262
}

ios/RNSentry.m

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -312,11 +312,7 @@ - (void)swizzleCallNativeModule:(Class)class {
312312

313313
RCT_EXPORT_METHOD(setUser:(NSDictionary *_Nonnull)user)
314314
{
315-
SentryUser *sentryUser = [[SentryUser alloc] initWithUserId:[RCTConvert NSString:user[@"userID"]]];
316-
sentryUser.email = [RCTConvert NSString:user[@"email"]];
317-
sentryUser.username = [RCTConvert NSString:user[@"username"]];
318-
sentryUser.extra = [RCTConvert NSDictionary:user[@"extra"]];
319-
SentryClient.sharedClient.user = sentryUser;
315+
SentryClient.sharedClient.user = [self createUser:user];
320316
}
321317

322318
RCT_EXPORT_METHOD(captureBreadcrumb:(NSDictionary * _Nonnull)breadcrumb)
@@ -334,13 +330,7 @@ - (void)swizzleCallNativeModule:(Class)class {
334330
{
335331
SentrySeverity level = [self sentrySeverityFromLevel:event[@"level"]];
336332

337-
SentryUser *user = nil;
338-
if (event[@"user"] != nil) {
339-
user = [[SentryUser alloc] initWithUserId:[NSString stringWithFormat:@"%@", event[@"user"][@"userID"]]];
340-
user.email = [NSString stringWithFormat:@"%@", event[@"user"][@"email"]];
341-
user.username = [NSString stringWithFormat:@"%@", event[@"user"][@"username"]];
342-
user.extra = [RCTConvert NSDictionary:event[@"user"][@"extra"]];
343-
}
333+
SentryUser *user = [self createUser:event[@"user"]];
344334

345335
SentryEvent *sentryEvent = [[SentryEvent alloc] initWithLevel:level];
346336
sentryEvent.eventId = event[@"event_id"];
@@ -370,6 +360,23 @@ - (void)addExceptionToEvent:(SentryEvent *)event type:(NSString *)type value:(NS
370360
event.exceptions = @[sentryException];
371361
}
372362

363+
- (SentryUser *_Nullable)createUser:(NSDictionary *_Nonnull)user {
364+
NSString *userId = nil;
365+
if (nil != user[@"userID"]) {
366+
userId = [NSString stringWithFormat:@"%@", user[@"userID"]];
367+
} else if (nil != user[@"userId"]) {
368+
userId = [NSString stringWithFormat:@"%@", user[@"userId"]];
369+
} else if (nil != user[@"id"]) {
370+
userId = [NSString stringWithFormat:@"%@", user[@"id"]];
371+
}
372+
SentryUser *sentryUser = nil;
373+
sentryUser = [[SentryUser alloc] initWithUserId:userId];
374+
sentryUser.email = [NSString stringWithFormat:@"%@", user[@"email"]];
375+
sentryUser.username = [NSString stringWithFormat:@"%@", user[@"username"]];
376+
sentryUser.extra = [RCTConvert NSDictionary:user[@"extra"]];
377+
return sentryUser;
378+
}
379+
373380
RCT_EXPORT_METHOD(crash)
374381
{
375382
[SentryClient.sharedClient crash];

0 commit comments

Comments
 (0)