Skip to content

Commit

Permalink
fix(feedback): Check for empty user (#11993)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
c298lee committed May 13, 2024
1 parent 1d2602c commit 1098627
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion packages/feedback/src/modal/integration.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,26 @@ import type {
FeedbackFormData,
FeedbackModalIntegration,
IntegrationFn,
User,
} from '@sentry/types';
import { h, render } from 'preact';
import { DOCUMENT } from '../constants';
import { Dialog } from './components/Dialog';
import { createDialogStyles } from './components/Dialog.css';

function getUser(): User | undefined {
const currentUser = getCurrentScope().getUser();
const isolationUser = getIsolationScope().getUser();
const globalUser = getGlobalScope().getUser();
if (currentUser && Object.keys(currentUser).length) {
return currentUser;
}
if (isolationUser && Object.keys(isolationUser).length) {
return isolationUser;
}
return globalUser;
}

export const feedbackModalIntegration = ((): FeedbackModalIntegration => {
return {
name: 'FeedbackModal',
Expand All @@ -19,7 +33,7 @@ export const feedbackModalIntegration = ((): FeedbackModalIntegration => {
createDialog: ({ options, screenshotIntegration, sendFeedback, shadow }: CreateDialogProps) => {
const shadowRoot = shadow as unknown as ShadowRoot;
const userKey = options.useSentryUser;
const user = getCurrentScope().getUser() || getIsolationScope().getUser() || getGlobalScope().getUser();
const user = getUser();

const el = DOCUMENT.createElement('div');
const style = createDialogStyles();
Expand Down

0 comments on commit 1098627

Please sign in to comment.