@@ -12,7 +12,7 @@ import type {
1212
1313import type { SirenProviderConfigProps } from '../types' ;
1414import { isNonEmptyArray , logger } from '../utils/commonUtils' ;
15- import { events , eventTypes } from '../utils/constants' ;
15+ import { events , eventTypes , TOKEN_VERIFICATION_FAILED } from '../utils/constants' ;
1616
1717type SirenContextProp = {
1818 siren : Siren | null ;
@@ -66,6 +66,8 @@ export const useSirenContext = (): SirenContextProp => useContext(SirenContext);
6666 * @param {React.ReactNode } props.children - Child components that will have access to the Siren context.
6767 */
6868const SirenProvider : React . FC < SirenProvider > = ( { config, children } ) => {
69+ let retryCount = 0 ;
70+
6971 const [ siren , setSiren ] = useState < Siren | null > ( null ) ;
7072
7173 useEffect ( ( ) => {
@@ -121,11 +123,19 @@ const SirenProvider: React.FC<SirenProvider> = ({ config, children }) => {
121123 return {
122124 token : config . userToken ,
123125 recipientId : config . recipientId ,
124- onError : ( error : SirenErrorType ) : void => logger . info ( `Error : ${ JSON . stringify ( error ) } ` ) ,
126+ onError : retryVerification ,
125127 actionCallbacks : actionCallbacks
126128 } ;
127129 } ;
128130
131+ const retryVerification = ( error : SirenErrorType ) => {
132+ if ( error . Code === TOKEN_VERIFICATION_FAILED && retryCount < 3 )
133+ setTimeout ( ( ) => {
134+ initialize ( ) ;
135+ retryCount ++ ;
136+ } , 5000 ) ;
137+ } ;
138+
129139 // Function to initialize the Siren SDK and fetch notifications
130140 const initialize = ( ) : void => {
131141 const dataParams : InitConfigType = getDataParams ( ) ;
0 commit comments