diff --git a/src/actions/me.ts b/src/actions/me.ts index 4e02a6e622..dc6c8fa2d9 100644 --- a/src/actions/me.ts +++ b/src/actions/me.ts @@ -1,4 +1,5 @@ import { selectAccount } from 'soapbox/selectors'; +import { setSentryAccount } from 'soapbox/sentry'; import KVStore from 'soapbox/storage/kv-store'; import { getAuthUserId, getAuthUserUrl } from 'soapbox/utils/auth'; @@ -8,6 +9,7 @@ import { loadCredentials } from './auth'; import { importFetchedAccount } from './importer'; import type { AxiosError, RawAxiosRequestHeaders } from 'axios'; +import type { Account } from 'soapbox/schemas'; import type { AppDispatch, RootState } from 'soapbox/store'; import type { APIEntity } from 'soapbox/types/entities'; @@ -88,10 +90,14 @@ const fetchMeRequest = () => ({ type: ME_FETCH_REQUEST, }); -const fetchMeSuccess = (me: APIEntity) => ({ - type: ME_FETCH_SUCCESS, - me, -}); +const fetchMeSuccess = (account: Account) => { + setSentryAccount(account); + + return { + type: ME_FETCH_SUCCESS, + me: account, + }; +}; const fetchMeFail = (error: APIEntity) => ({ type: ME_FETCH_FAIL, diff --git a/src/sentry.ts b/src/sentry.ts index a76d432c06..4ef1ea77ea 100644 --- a/src/sentry.ts +++ b/src/sentry.ts @@ -1,3 +1,5 @@ +import type { Account } from './schemas'; + /** Start Sentry. */ async function startSentry(dsn: string): Promise { const [Sentry, { Integrations: Integrations }] = await Promise.all([ @@ -36,4 +38,14 @@ async function startSentry(dsn: string): Promise { }); } -export { startSentry }; \ No newline at end of file +/** Associate the account with Sentry events. */ +async function setSentryAccount(account: Account) { + const Sentry = await import('@sentry/react'); + + Sentry.setUser({ + id: account.id, + username: account.acct, + }); +} + +export { startSentry, setSentryAccount }; \ No newline at end of file