From b54260bc1f1a2f20603ace090cb392f610b7f08f Mon Sep 17 00:00:00 2001 From: Adw8 Date: Tue, 30 Jul 2024 16:21:01 +0530 Subject: [PATCH] Implement expiration handler for access token --- src/pages/OnboardingSuccess.tsx | 15 ++++----------- src/pages/UserVerification.tsx | 6 +++--- src/utils/sumsub.ts | 8 +++++--- 3 files changed, 12 insertions(+), 17 deletions(-) diff --git a/src/pages/OnboardingSuccess.tsx b/src/pages/OnboardingSuccess.tsx index 0e439eb..4249e83 100644 --- a/src/pages/OnboardingSuccess.tsx +++ b/src/pages/OnboardingSuccess.tsx @@ -7,7 +7,7 @@ import { Registry } from "@cerc-io/registry-sdk"; import SumsubWebSdk from "@sumsub/websdk-react"; import { MessageHandler } from "@sumsub/websdk"; -import { accessTokenExpirationHandler, config, fetchAccessToken, options } from "../utils/sumsub"; +import { config, fetchAccessToken, getAccessTokenExpirationHandler, options } from "../utils/sumsub"; interface Participant { cosmosAddress: string; @@ -31,12 +31,7 @@ const OnboardingSuccess = () => { const [loading, setLoading] = useState(true); const messageHandler: MessageHandler = (event, payload) => { - console.log('sumsubEvent:', event); - - if (payload) { - console.log("Event payload is: ", payload); - } - + console.log('sumsubEvent:', event, payload); }; useEffect(() => { @@ -69,12 +64,10 @@ const OnboardingSuccess = () => { }; if (cosmosAddress) { - console.log("Cosmos addy: ", cosmosAddress); getToken(cosmosAddress).catch(error => { console.error(error); alert("Failed to fetch token"); }); - } }, [cosmosAddress]); @@ -112,10 +105,10 @@ const OnboardingSuccess = () => { KYC Status - {!loading && token && ( + {!loading && token && cosmosAddress && ( { const [kycId, setKycId] = useState('unknown'); @@ -88,10 +88,10 @@ const UserVerification = () => { User verification
- {!loading && token && ( + {!loading && token && userId && ( { - alert("Please renew token"); - return "Token expired"; +export const getAccessTokenExpirationHandler = (userId: string) => { + return async () => { + const newToken = await fetchAccessToken(userId); + return newToken; + } };