Skip to content

Commit

Permalink
fix: get user id
Browse files Browse the repository at this point in the history
  • Loading branch information
IsaccoSordo committed Mar 25, 2024
1 parent f844efe commit f1e6210
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions packages/beacon-ui/src/components/bug-report-form/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -77,15 +77,17 @@ const BugReportForm = (props: any) => {
console.error(error.message)
}

if (
(!beaconResult[StorageKey.USER_ID] || !beaconResult[StorageKey.USER_ID].length) &&
localStorage
) {
const key = Object.keys(localStorage).find((key) => key.includes('user-id'))
key?.length && (beaconResult[StorageKey.USER_ID] = localStorage.getItem(key))
return [beaconResult, wcResult]
}

const getUserId = (): string => {
if (!localStorage) {
return 'UNKOWN'
}

return [beaconResult, wcResult]
const key = Object.keys(localStorage).find((key) => key.includes('user-id'))

return key && key.length ? localStorage.getItem(key) ?? 'UNKOWN' : 'UNKOWN'
}

createEffect(() => {
Expand All @@ -106,7 +108,9 @@ const BugReportForm = (props: any) => {

const request: BugReportRequest = {
userId:
beaconState[StorageKey.USER_ID] ?? localStorage.getItem(StorageKey.USER_ID) ?? 'UNKOWN',
beaconState[StorageKey.USER_ID] && beaconState[StorageKey.USER_ID].length
? beaconState[StorageKey.USER_ID]
: getUserId(),
title: title(),
sdkVersion: SDK_VERSION,
description: description(),
Expand Down

0 comments on commit f1e6210

Please sign in to comment.