Implement expiration handler for access token
This commit is contained in:
parent
5f356c8bce
commit
b54260bc1f
@ -7,7 +7,7 @@ import { Registry } from "@cerc-io/registry-sdk";
|
|||||||
import SumsubWebSdk from "@sumsub/websdk-react";
|
import SumsubWebSdk from "@sumsub/websdk-react";
|
||||||
import { MessageHandler } from "@sumsub/websdk";
|
import { MessageHandler } from "@sumsub/websdk";
|
||||||
|
|
||||||
import { accessTokenExpirationHandler, config, fetchAccessToken, options } from "../utils/sumsub";
|
import { config, fetchAccessToken, getAccessTokenExpirationHandler, options } from "../utils/sumsub";
|
||||||
|
|
||||||
interface Participant {
|
interface Participant {
|
||||||
cosmosAddress: string;
|
cosmosAddress: string;
|
||||||
@ -31,12 +31,7 @@ const OnboardingSuccess = () => {
|
|||||||
const [loading, setLoading] = useState<boolean>(true);
|
const [loading, setLoading] = useState<boolean>(true);
|
||||||
|
|
||||||
const messageHandler: MessageHandler = (event, payload) => {
|
const messageHandler: MessageHandler = (event, payload) => {
|
||||||
console.log('sumsubEvent:', event);
|
console.log('sumsubEvent:', event, payload);
|
||||||
|
|
||||||
if (payload) {
|
|
||||||
console.log("Event payload is: ", payload);
|
|
||||||
}
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
@ -69,12 +64,10 @@ const OnboardingSuccess = () => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
if (cosmosAddress) {
|
if (cosmosAddress) {
|
||||||
console.log("Cosmos addy: ", cosmosAddress);
|
|
||||||
getToken(cosmosAddress).catch(error => {
|
getToken(cosmosAddress).catch(error => {
|
||||||
console.error(error);
|
console.error(error);
|
||||||
alert("Failed to fetch token");
|
alert("Failed to fetch token");
|
||||||
});
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
}, [cosmosAddress]);
|
}, [cosmosAddress]);
|
||||||
|
|
||||||
@ -112,10 +105,10 @@ const OnboardingSuccess = () => {
|
|||||||
</pre>
|
</pre>
|
||||||
</Box>
|
</Box>
|
||||||
<Typography variant="h5">KYC Status</Typography>
|
<Typography variant="h5">KYC Status</Typography>
|
||||||
{!loading && token && (
|
{!loading && token && cosmosAddress && (
|
||||||
<SumsubWebSdk
|
<SumsubWebSdk
|
||||||
accessToken={token}
|
accessToken={token}
|
||||||
expirationHandler={accessTokenExpirationHandler}
|
expirationHandler={getAccessTokenExpirationHandler(cosmosAddress)}
|
||||||
config={config}
|
config={config}
|
||||||
options={options}
|
options={options}
|
||||||
onMessage={messageHandler}
|
onMessage={messageHandler}
|
||||||
|
@ -6,7 +6,7 @@ import SumsubWebSdk from '@sumsub/websdk-react';
|
|||||||
import { MessageHandler } from '@sumsub/websdk';
|
import { MessageHandler } from '@sumsub/websdk';
|
||||||
import { EventPayload } from '@sumsub/websdk/types/types';
|
import { EventPayload } from '@sumsub/websdk/types/types';
|
||||||
|
|
||||||
import { accessTokenExpirationHandler, config, fetchAccessToken, options } from '../utils/sumsub';
|
import { config, fetchAccessToken, getAccessTokenExpirationHandler, options } from '../utils/sumsub';
|
||||||
|
|
||||||
const UserVerification = () => {
|
const UserVerification = () => {
|
||||||
const [kycId, setKycId] = useState<string>('unknown');
|
const [kycId, setKycId] = useState<string>('unknown');
|
||||||
@ -88,10 +88,10 @@ const UserVerification = () => {
|
|||||||
<Typography variant="h5">User verification</Typography>
|
<Typography variant="h5">User verification</Typography>
|
||||||
<div id="sumsub-websdk-container"></div>
|
<div id="sumsub-websdk-container"></div>
|
||||||
</Box>
|
</Box>
|
||||||
{!loading && token && (
|
{!loading && token && userId && (
|
||||||
<SumsubWebSdk
|
<SumsubWebSdk
|
||||||
accessToken={token}
|
accessToken={token}
|
||||||
expirationHandler={accessTokenExpirationHandler}
|
expirationHandler={getAccessTokenExpirationHandler(userId)}
|
||||||
config={config}
|
config={config}
|
||||||
options={options}
|
options={options}
|
||||||
onMessage={messageHandler}
|
onMessage={messageHandler}
|
||||||
|
@ -25,7 +25,9 @@ export const options = {
|
|||||||
adaptIframeHeight: true,
|
adaptIframeHeight: true,
|
||||||
};
|
};
|
||||||
|
|
||||||
export const accessTokenExpirationHandler = async () => {
|
export const getAccessTokenExpirationHandler = (userId: string) => {
|
||||||
alert("Please renew token");
|
return async () => {
|
||||||
return "Token expired";
|
const newToken = await fetchAccessToken(userId);
|
||||||
|
return newToken;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user