From 9af9a0284e77b746b3e4edec9cc698703c98676a Mon Sep 17 00:00:00 2001 From: Amruth Pillai Date: Sat, 3 Dec 2022 00:15:08 +0100 Subject: [PATCH] set sentry user ID, if available and applicable --- client/wrappers/SentryWrapper.tsx | 17 +++++++++++++++++ client/wrappers/index.tsx | 21 +++++++++++---------- 2 files changed, 28 insertions(+), 10 deletions(-) create mode 100644 client/wrappers/SentryWrapper.tsx diff --git a/client/wrappers/SentryWrapper.tsx b/client/wrappers/SentryWrapper.tsx new file mode 100644 index 00000000..0895a187 --- /dev/null +++ b/client/wrappers/SentryWrapper.tsx @@ -0,0 +1,17 @@ +import * as Sentry from '@sentry/nextjs'; +import { useEffect } from 'react'; + +import { useAppSelector } from '@/store/hooks'; + +const SentryWrapper: React.FC> = ({ children }) => { + const user = useAppSelector((state) => state.auth.user); + + useEffect(() => { + const sentryUser: Sentry.User | null = user && { ...user, id: user?.id.toString() }; + Sentry.setUser(sentryUser); + }, [user]); + + return <>{children}; +}; + +export default SentryWrapper; diff --git a/client/wrappers/index.tsx b/client/wrappers/index.tsx index 7251792e..27060c2a 100644 --- a/client/wrappers/index.tsx +++ b/client/wrappers/index.tsx @@ -1,17 +1,18 @@ import DateWrapper from './DateWrapper'; import FontWrapper from './FontWrapper'; +import SentryWrapper from './SentryWrapper'; import ThemeWrapper from './ThemeWrapper'; -const WrapperRegistry: React.FC> = ({ children }) => { - return ( - - - +const WrapperRegistry: React.FC> = ({ children }) => ( + + + + <>{children} - - - - ); -}; + + + + +); export default WrapperRegistry;