Skip to content

The open alternative to Salesforce, designed for AI.

fix(front): unwrap react-qr-code default export to fix 2FA crash on prod (#21804)

Charles Bochetd88eb6c16b01
diff --git a/packages/twenty-front/src/modules/auth/sign-in-up/components/internal/SignInUpTwoFactorAuthenticationProvision.tsx b/packages/twenty-front/src/modules/auth/sign-in-up/components/internal/SignInUpTwoFactorAuthenticationProvision.tsx
index d997050f7e4..2a8aaa30bec 100644
--- a/packages/twenty-front/src/modules/auth/sign-in-up/components/internal/SignInUpTwoFactorAuthenticationProvision.tsx
+++ b/packages/twenty-front/src/modules/auth/sign-in-up/components/internal/SignInUpTwoFactorAuthenticationProvision.tsx
@@ -7,7 +7,7 @@ import {
import { extractSecretFromOtpUri } from '@/settings/two-factor-authentication/utils/extractSecretFromOtpUri';
import { styled } from '@linaria/react';
import { Trans, useLingui } from '@lingui/react/macro';
-import QRCode from 'react-qr-code';
+import QRCodeModule from 'react-qr-code';
import { useSetAtomState } from '@/ui/utilities/state/jotai/hooks/useSetAtomState';
import { IconCopy } from 'twenty-ui/icon';
import { Loader } from 'twenty-ui/feedback';
@@ -15,8 +15,11 @@ import { MainButton } from 'twenty-ui/input';
import { useContext } from 'react';
import { ThemeContext, themeCssVariables } from 'twenty-ui/theme-constants';
import { useAtomStateValue } from '@/ui/utilities/state/jotai/hooks/useAtomStateValue';
+import { resolveCjsModuleDefaultExport } from '~/utils/resolveCjsModuleDefaultExport';
import { useCopyToClipboard } from '~/hooks/useCopyToClipboard';
+const QRCode = resolveCjsModuleDefaultExport(QRCodeModule);
+
const StyledMainContentContainer = styled.div`
margin-bottom: ${themeCssVariables.spacing[8]};
margin-top: ${themeCssVariables.spacing[4]};
diff --git a/packages/twenty-front/src/pages/settings/profile/SettingsTwoFactorAuthenticationMethod.tsx b/packages/twenty-front/src/pages/settings/profile/SettingsTwoFactorAuthenticationMethod.tsx
index 1171f6b492a..924bc15bd57 100644
--- a/packages/twenty-front/src/pages/settings/profile/SettingsTwoFactorAuthenticationMethod.tsx
+++ b/packages/twenty-front/src/pages/settings/profile/SettingsTwoFactorAuthenticationMethod.tsx
@@ -1,7 +1,7 @@
import { styled } from '@linaria/react';
import { Trans, useLingui } from '@lingui/react/macro';
import { FormProvider } from 'react-hook-form';
-import QRCode from 'react-qr-code';
+import QRCodeModule from 'react-qr-code';
import { qrCodeState } from '@/auth/states/qrCode';
import { SaveAndCancelButtons } from '@/settings/components/SaveAndCancelButtons/SaveAndCancelButtons';
@@ -20,8 +20,11 @@ import { Loader } from 'twenty-ui/feedback';
import { Section } from 'twenty-ui/layout';
import { useAtomStateValue } from '@/ui/utilities/state/jotai/hooks/useAtomStateValue';
import { themeCssVariables } from 'twenty-ui/theme-constants';
+import { resolveCjsModuleDefaultExport } from '~/utils/resolveCjsModuleDefaultExport';
import { useCopyToClipboard } from '~/hooks/useCopyToClipboard';
+const QRCode = resolveCjsModuleDefaultExport(QRCodeModule);
+
const StyledQRCodeContainer = styled.div`
align-items: flex-start;
display: flex;
diff --git a/packages/twenty-front/src/utils/resolveCjsModuleDefaultExport.ts b/packages/twenty-front/src/utils/resolveCjsModuleDefaultExport.ts
new file mode 100644
index 00000000000..a534904a9ea
--- /dev/null
+++ b/packages/twenty-front/src/utils/resolveCjsModuleDefaultExport.ts
@@ -0,0 +1,10 @@
+import { isDefined } from 'twenty-shared/utils';
+
+export const resolveCjsModuleDefaultExport = <TDefaultExport>(
+ importedModule: TDefaultExport,
+): TDefaultExport => {
+ const defaultExport = (importedModule as { default?: TDefaultExport })
+ .default;
+
+ return isDefined(defaultExport) ? defaultExport : importedModule;
+};