Skip to content

Commit 91d44ff

Browse files
fix: Handle invalid credentials error case
1 parent 1393b14 commit 91d44ff

File tree

4 files changed

+30
-6
lines changed

4 files changed

+30
-6
lines changed

src/components/sirenInbox.tsx

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ const {
2121
events,
2222
TOKEN_VERIFICATION_PENDING,
2323
MAXIMUM_ITEMS_PER_FETCH,
24-
VerificationStatus
24+
VerificationStatus,
25+
errorMap
2526
} = Constants;
2627
const { applyTheme, isNonEmptyArray, updateNotifications } = CommonUtils;
2728

@@ -127,7 +128,13 @@ const SirenInbox = (props: SirenInboxProps): ReactElement => {
127128

128129
useEffect(() => {
129130
// Initialize Siren SDK and start polling notifications
130-
if (verificationStatus !== VerificationStatus.PENDING && siren) initialize();
131+
if (verificationStatus !== VerificationStatus.PENDING && siren) {
132+
initialize();
133+
} else if(verificationStatus === VerificationStatus.FAILED) {
134+
setIsError(true);
135+
setIsLoading(false);
136+
if (onError) onError(errorMap.MISSING_PARAMETER);
137+
}
131138
}, [siren, verificationStatus]);
132139

133140
useEffect(() => {

src/components/sirenInboxIcon.tsx

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,15 @@ import { useSirenContext } from './sirenProvider';
88
import type { SirenInboxIconProps } from '../types';
99
import { CommonUtils, Constants } from '../utils';
1010

11-
const { ThemeMode, defaultBadgeStyle, eventTypes, events, defaultStyles } = Constants;
11+
const {
12+
ThemeMode,
13+
defaultBadgeStyle,
14+
eventTypes,
15+
events,
16+
defaultStyles,
17+
VerificationStatus,
18+
errorMap
19+
} = Constants;
1220
const { logger } = CommonUtils;
1321

1422
/**
@@ -42,7 +50,7 @@ const SirenInboxIcon = (props: SirenInboxIconProps) => {
4250
onError = () => null
4351
} = props;
4452

45-
const { siren } = useSirenContext();
53+
const { siren, verificationStatus } = useSirenContext();
4654

4755
const [unviewedCount, seUnviewedCount] = useState<number>(0);
4856

@@ -79,8 +87,10 @@ const SirenInboxIcon = (props: SirenInboxIconProps) => {
7987
}, []);
8088

8189
useEffect(() => {
82-
initialize();
83-
}, [siren]);
90+
if (verificationStatus !== VerificationStatus.PENDING && siren) initialize();
91+
else if (verificationStatus === VerificationStatus.FAILED && onError)
92+
onError(errorMap.MISSING_PARAMETER);
93+
}, [siren, verificationStatus]);
8494

8595
useEffect(() => {
8696
if (unviewedCount > 0) logger.info(`unviewed notification count : ${unviewedCount}`);

src/components/sirenProvider.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,8 @@ const SirenProvider: React.FC<SirenProvider> = ({ config, children }) => {
8484
stopRealTimeFetch();
8585
sendResetDataEvents();
8686
initialize();
87+
} else {
88+
setVerificationStatus(VerificationStatus.FAILED);
8789
}
8890
}, [config]);
8991

src/utils/constants.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,11 @@ export const errorMap = {
9797
Type: 'ERROR',
9898
Code: 'MISSING_PARAMETER',
9999
Message: 'Missing required parameter'
100+
},
101+
INVALID_CREDENTIALS: {
102+
Type: 'ERROR',
103+
Code: 'INVALID_CREDENTIALS',
104+
Message: 'Invalid credentials found. Please check your token and recipient ID'
100105
}
101106
};
102107

0 commit comments

Comments
 (0)