Skip to content

Commit

Permalink
Merge pull request #774 from supertokens/feat/add-date-provider-docs
Browse files Browse the repository at this point in the history
feat: Add docs for using DateProvider in SessionClaimValidator
  • Loading branch information
rishabhpoddar authored Jan 29, 2024
2 parents 7588497 + 9ecb9d1 commit 2c0a1f8
Show file tree
Hide file tree
Showing 7 changed files with 119 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,25 @@ type ClaimValidationResult = { isValid: true } | { isValid: false; reason?: any


- The `refresh` function is the same as the one in the frontend claim interface.
- `shouldRefresh` is function which determines if the claim should be checked against the backend before calling `validate`. This usually returns `true` if the claim value is too old or if it is not present in the `accessTokenPayload`.
- `shouldRefresh` is function which determines if the claim should be checked against the backend before calling `validate`. This usually returns `true` if the claim value is too old or if it is not present in the `accessTokenPayload`. When implementing this function for a `SessionClaimValidator` and using `Date.now`, it's advisable to use `DateProvider.now` from our SDK. This mitigates potential clock skew issues by accounting for the time difference between the frontend and backend. Use `DateProvider` as shown:

<PreBuiltUIContent>

```tsx
import { DateProviderReference } from "supertokens-auth-react/utils/dateProvider";
DateProviderReference.getReferenceOrThrow().dateProvider.now();
```

</PreBuiltUIContent>

<CustomUIContent>

```tsx
import { DateProviderReference } from "supertokens-web-js/utils/dateProvider";
DateProviderReference.getReferenceOrThrow().dateProvider.now();
```
</CustomUIContent>

- The `validate` function checks the `accessTokenPayload` for the value of the claim and returns an appropriate response.

<PreBuiltUIContent>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,25 @@ type ClaimValidationResult = { isValid: true } | { isValid: false; reason?: any


- The `refresh` function is the same as the one in the frontend claim interface.
- `shouldRefresh` is function which determines if the claim should be checked against the backend before calling `validate`. This usually returns `true` if the claim value is too old or if it is not present in the `accessTokenPayload`.
- `shouldRefresh` is function which determines if the claim should be checked against the backend before calling `validate`. This usually returns `true` if the claim value is too old or if it is not present in the `accessTokenPayload`. When implementing this function for a `SessionClaimValidator` and using `Date.now`, it's advisable to use `DateProvider.now` from our SDK. This mitigates potential clock skew issues by accounting for the time difference between the frontend and backend. Use `DateProvider` as shown:

<PreBuiltUIContent>

```tsx
import { DateProviderReference } from "supertokens-auth-react/utils/dateProvider";
DateProviderReference.getReferenceOrThrow().dateProvider.now();
```

</PreBuiltUIContent>

<CustomUIContent>

```tsx
import { DateProviderReference } from "supertokens-web-js/utils/dateProvider";
DateProviderReference.getReferenceOrThrow().dateProvider.now();
```
</CustomUIContent>

- The `validate` function checks the `accessTokenPayload` for the value of the claim and returns an appropriate response.

<PreBuiltUIContent>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,25 @@ type ClaimValidationResult = { isValid: true } | { isValid: false; reason?: any


- The `refresh` function is the same as the one in the frontend claim interface.
- `shouldRefresh` is function which determines if the claim should be checked against the backend before calling `validate`. This usually returns `true` if the claim value is too old or if it is not present in the `accessTokenPayload`.
- `shouldRefresh` is function which determines if the claim should be checked against the backend before calling `validate`. This usually returns `true` if the claim value is too old or if it is not present in the `accessTokenPayload`. When implementing this function for a `SessionClaimValidator` and using `Date.now`, it's advisable to use `DateProvider.now` from our SDK. This mitigates potential clock skew issues by accounting for the time difference between the frontend and backend. Use `DateProvider` as shown:

<PreBuiltUIContent>

```tsx
import { DateProviderReference } from "supertokens-auth-react/utils/dateProvider";
DateProviderReference.getReferenceOrThrow().dateProvider.now();
```

</PreBuiltUIContent>

<CustomUIContent>

```tsx
import { DateProviderReference } from "supertokens-web-js/utils/dateProvider";
DateProviderReference.getReferenceOrThrow().dateProvider.now();
```
</CustomUIContent>

- The `validate` function checks the `accessTokenPayload` for the value of the claim and returns an appropriate response.

<PreBuiltUIContent>
Expand Down
10 changes: 5 additions & 5 deletions v2/src/plugins/codeTypeChecking/jsEnv/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,14 +55,14 @@
"react-router-dom5": "npm:react-router-dom@^5.3.0",
"socket.io": "^4.6.1",
"socketio": "^1.0.0",
"supertokens-auth-react": "^0.36.0",
"supertokens-auth-react": "^0.37.0",
"supertokens-node": "^16.7.0",
"supertokens-node7": "npm:[email protected]",
"supertokens-react-native": "^4.0.0",
"supertokens-web-js": "^0.8.0",
"supertokens-web-js-script": "github:supertokens/supertokens-web-js#0.8",
"supertokens-website": "^17.0.0",
"supertokens-website-script": "github:supertokens/supertokens-website#17.0",
"supertokens-web-js": "^0.9.0",
"supertokens-web-js-script": "github:supertokens/supertokens-web-js#0.9",
"supertokens-website": "^18.0.0",
"supertokens-website-script": "github:supertokens/supertokens-website#18.0",
"typescript": "^4.9.5"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,25 @@ type ClaimValidationResult = { isValid: true } | { isValid: false; reason?: any


- The `refresh` function is the same as the one in the frontend claim interface.
- `shouldRefresh` is function which determines if the claim should be checked against the backend before calling `validate`. This usually returns `true` if the claim value is too old or if it is not present in the `accessTokenPayload`.
- `shouldRefresh` is function which determines if the claim should be checked against the backend before calling `validate`. This usually returns `true` if the claim value is too old or if it is not present in the `accessTokenPayload`. When implementing this function for a `SessionClaimValidator` and using `Date.now`, it's advisable to use `DateProvider.now` from our SDK. This mitigates potential clock skew issues by accounting for the time difference between the frontend and backend. Use `DateProvider` as shown:

<PreBuiltUIContent>

```tsx
import { DateProviderReference } from "supertokens-auth-react/utils/dateProvider";
DateProviderReference.getReferenceOrThrow().dateProvider.now();
```

</PreBuiltUIContent>

<CustomUIContent>

```tsx
import { DateProviderReference } from "supertokens-web-js/utils/dateProvider";
DateProviderReference.getReferenceOrThrow().dateProvider.now();
```
</CustomUIContent>

- The `validate` function checks the `accessTokenPayload` for the value of the claim and returns an appropriate response.

<PreBuiltUIContent>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,25 @@ type ClaimValidationResult = { isValid: true } | { isValid: false; reason?: any


- The `refresh` function is the same as the one in the frontend claim interface.
- `shouldRefresh` is function which determines if the claim should be checked against the backend before calling `validate`. This usually returns `true` if the claim value is too old or if it is not present in the `accessTokenPayload`.
- `shouldRefresh` is function which determines if the claim should be checked against the backend before calling `validate`. This usually returns `true` if the claim value is too old or if it is not present in the `accessTokenPayload`. When implementing this function for a `SessionClaimValidator` and using `Date.now`, it's advisable to use `DateProvider.now` from our SDK. This mitigates potential clock skew issues by accounting for the time difference between the frontend and backend. Use `DateProvider` as shown:

<PreBuiltUIContent>

```tsx
import { DateProviderReference } from "supertokens-auth-react/utils/dateProvider";
DateProviderReference.getReferenceOrThrow().dateProvider.now();
```

</PreBuiltUIContent>

<CustomUIContent>

```tsx
import { DateProviderReference } from "supertokens-web-js/utils/dateProvider";
DateProviderReference.getReferenceOrThrow().dateProvider.now();
```
</CustomUIContent>

- The `validate` function checks the `accessTokenPayload` for the value of the claim and returns an appropriate response.

<PreBuiltUIContent>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,25 @@ type ClaimValidationResult = { isValid: true } | { isValid: false; reason?: any


- The `refresh` function is the same as the one in the frontend claim interface.
- `shouldRefresh` is function which determines if the claim should be checked against the backend before calling `validate`. This usually returns `true` if the claim value is too old or if it is not present in the `accessTokenPayload`.
- `shouldRefresh` is function which determines if the claim should be checked against the backend before calling `validate`. This usually returns `true` if the claim value is too old or if it is not present in the `accessTokenPayload`. When implementing this function for a `SessionClaimValidator` and using `Date.now`, it's advisable to use `DateProvider.now` from our SDK. This mitigates potential clock skew issues by accounting for the time difference between the frontend and backend. Use `DateProvider` as shown:

<PreBuiltUIContent>

```tsx
import { DateProviderReference } from "supertokens-auth-react/utils/dateProvider";
DateProviderReference.getReferenceOrThrow().dateProvider.now();
```

</PreBuiltUIContent>

<CustomUIContent>

```tsx
import { DateProviderReference } from "supertokens-web-js/utils/dateProvider";
DateProviderReference.getReferenceOrThrow().dateProvider.now();
```
</CustomUIContent>

- The `validate` function checks the `accessTokenPayload` for the value of the claim and returns an appropriate response.

<PreBuiltUIContent>
Expand Down

0 comments on commit 2c0a1f8

Please sign in to comment.