Skip to content

Commit

Permalink
chore(docs): Update systemClockOffset example (#5367)
Browse files Browse the repository at this point in the history
Co-authored-by: Scott Rees <6165315+reesscot@users.noreply.github.com>
  • Loading branch information
esauerbo and reesscot committed Jul 8, 2024
1 parent 70354b0 commit e688f5d
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ Yes, this use case is supported. Please select "Self Managed Cognito Resource"
<InlineFilter filters={['react']}>
### 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).
</InlineFilter>

0 comments on commit e688f5d

Please sign in to comment.