Skip to content

Commit 1098627

Browse files
authored
fix(feedback): Check for empty user (#11993)
When getting the user from the scope, the user can also be an empty object, which doesn't work with null coalescing. This checks to see if the user exists and that it's not empty in all scopes Fixes getsentry/sentry#70347
1 parent 1d2602c commit 1098627

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

packages/feedback/src/modal/integration.tsx

+15-1
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,26 @@ import type {
55
FeedbackFormData,
66
FeedbackModalIntegration,
77
IntegrationFn,
8+
User,
89
} from '@sentry/types';
910
import { h, render } from 'preact';
1011
import { DOCUMENT } from '../constants';
1112
import { Dialog } from './components/Dialog';
1213
import { createDialogStyles } from './components/Dialog.css';
1314

15+
function getUser(): User | undefined {
16+
const currentUser = getCurrentScope().getUser();
17+
const isolationUser = getIsolationScope().getUser();
18+
const globalUser = getGlobalScope().getUser();
19+
if (currentUser && Object.keys(currentUser).length) {
20+
return currentUser;
21+
}
22+
if (isolationUser && Object.keys(isolationUser).length) {
23+
return isolationUser;
24+
}
25+
return globalUser;
26+
}
27+
1428
export const feedbackModalIntegration = ((): FeedbackModalIntegration => {
1529
return {
1630
name: 'FeedbackModal',
@@ -19,7 +33,7 @@ export const feedbackModalIntegration = ((): FeedbackModalIntegration => {
1933
createDialog: ({ options, screenshotIntegration, sendFeedback, shadow }: CreateDialogProps) => {
2034
const shadowRoot = shadow as unknown as ShadowRoot;
2135
const userKey = options.useSentryUser;
22-
const user = getCurrentScope().getUser() || getIsolationScope().getUser() || getGlobalScope().getUser();
36+
const user = getUser();
2337

2438
const el = DOCUMENT.createElement('div');
2539
const style = createDialogStyles();

0 commit comments

Comments
 (0)