Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use /status to get time drift before sending any intents #605

Merged
merged 8 commits into from
Nov 7, 2024

Conversation

patrislav
Copy link
Member

No description provided.

packages/waas/src/auth.ts Outdated Show resolved Hide resolved
packages/waas/src/intents/base.ts Show resolved Hide resolved
const res = await fetch(`${this.config.rpcServer}/status`)
const date = res.headers.get('Date')
if (!date) {
throw new Error('missing Date header value')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

change error to, failed to get Date header value from /status ... and probably better is to have a well-defined error in the waas ridl for any error type.. but the above message will do for now

packages/waas/src/auth.ts Show resolved Hide resolved
@@ -11,9 +11,22 @@ export type SignedIntent<T> = Omit<RawIntent, 'data'> & { data: T }
const INTENTS_VERSION = 1
const VERSION = `${INTENTS_VERSION} (Web ${PACKAGE_VERSION})`

export function getTimeDrift() {
const drift = sessionStorage.getItem('timeDrift')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

your code will throw in react native and node


export function getTimeDrift() {
if (isSessionStorageAvailable()) {
const drift = sessionStorage.getItem(timeDriftKey)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should we use window.sessionStorage.getItem(..) to be explicit..? the "window" part that is..?

@pkieltyka pkieltyka merged commit 8a42ef2 into master Nov 7, 2024
22 checks passed
@pkieltyka pkieltyka deleted the waas-track-time-drift branch November 7, 2024 15:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants