From e688f5d503444a8b87cdad537093a3187922f758 Mon Sep 17 00:00:00 2001 From: Emma Sauerborn <70536670+esauerbo@users.noreply.github.com> Date: Mon, 8 Jul 2024 18:03:35 -0400 Subject: [PATCH] chore(docs): Update systemClockOffset example (#5367) Co-authored-by: Scott Rees <6165315+reesscot@users.noreply.github.com> --- ...ustomization.system-clock-offset.react.mdx | 23 +++++++++++-------- .../liveness/troubleshooting/index.page.mdx | 2 +- 2 files changed, 15 insertions(+), 10 deletions(-) diff --git a/docs/src/pages/[platform]/connected-components/liveness/customization/customization.system-clock-offset.react.mdx b/docs/src/pages/[platform]/connected-components/liveness/customization/customization.system-clock-offset.react.mdx index c5b96122807..ae4c6706f09 100644 --- a/docs/src/pages/[platform]/connected-components/liveness/customization/customization.system-clock-offset.react.mdx +++ b/docs/src/pages/[platform]/connected-components/liveness/customization/customization.system-clock-offset.react.mdx @@ -14,25 +14,30 @@ function MyComponent() { const [createLivenessApiData, setCreateLivenessApiData] = React.useState(null); /* - * 1. Check whether the difference between server time and device time - * is greater than 5 minutes, and if so, return the offset in milliseconds - * This logic should be adjusted based on the server response and your use case + * 1. Check whether the difference between server time and device time is + * greater than or equal to 5 minutes, and if so, return the offset in milliseconds. + * This logic should be adjusted based on the server response and use case */ - const getSystemClockOffset = (serverDate: string | undefined) => { + const getSystemClockOffset = (serverTime: number) => { + const maxSupportedClockSkew = 5 * 60 * 1000; // 5 minutes const deviceTime = Date.now(); - const serverTime = new Date(serverDate).getTime(); const delta = serverTime ? serverTime - deviceTime : 0; - return Math.abs(delta) > maxSupportedClockSkew ? delta : undefined; + return Math.abs(delta) >= maxSupportedClockSkew ? delta : undefined; } React.useEffect(() => { /* - * This should be replaced with your own API call to create a session + * Replace with your own API call to create a session */ const response = await fetch(`/api/createSession`); const body = await response.json(); // { sessionId: 'mockSessionId' } - const systemClockOffset = getSystemClockOffset(response.headers['date']) - setCreateLivenessApiData(body, systemClockOffset); + /* + * Replace serverTime with the actual server date, + * which can be retrieved from the response headers or your custom backend. + */ + const serverTime = response.headers['date'] + const systemClockOffset = getSystemClockOffset(serverTime) + setCreateLivenessApiData({body, systemClockOffset}); }, []); return ( diff --git a/docs/src/pages/[platform]/connected-components/liveness/troubleshooting/index.page.mdx b/docs/src/pages/[platform]/connected-components/liveness/troubleshooting/index.page.mdx index 2acca8f32aa..6e70b236979 100644 --- a/docs/src/pages/[platform]/connected-components/liveness/troubleshooting/index.page.mdx +++ b/docs/src/pages/[platform]/connected-components/liveness/troubleshooting/index.page.mdx @@ -51,7 +51,7 @@ Yes, this use case is supported. Please select "Self Managed Cognito Resource" ### InvalidSignatureException: Signature not yet current -The signature verification on the Rekognition streaming websocket connection was rejected due to a clock skew greater than 5 minutes. Clock skew represents the difference between a user's device time and AWS server time, and any clock skew larger than 5 minutes will be rejected by default. Below are some common reasons for encountering this error along with suggestions for resolving them. +The signature verification on the Rekognition streaming websocket connection was rejected due to a clock skew greater than or equal to 5 minutes. Clock skew represents the difference between a user's device time and AWS server time, and any clock skew of 5 minutes or larger will be rejected by default. Below are some common reasons for encountering this error along with suggestions for resolving them. 1. **The time on the user's device is inaccurate.** Ensure that the date and time on the user's device are accurate and match their time zone. 2. **User is in a new time zone that is not reflected on their device, or living between and frequently switching time zones.** If users cannot adjust their device time, you can pass `systemClockOffset` to the [`FaceLivenessDetectorCore` config](../liveness#facelivenessdetectorcoreconfig), which will be applied as an offset in milliseconds to the AWS server time. See an example [here](../liveness/customization#system-clock-offset). \ No newline at end of file