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

fix: use DateProvider in EmailVerificationClaim #103

Merged
merged 31 commits into from
Jan 29, 2024
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
84c5bdd
Use DateProvider in EmailVerificationClaim
anku255 Jan 11, 2024
e4a1534
Rename DateProvider to dateProvider
anku255 Jan 12, 2024
dce825c
Add dateProvider utils export
anku255 Jan 15, 2024
dfefab3
PR changes
anku255 Jan 16, 2024
b3c458b
bug: Ensure SuperTokens is initialized before checking for MultiTenancy
prateek3255 Jan 17, 2024
b4a90dd
Update Changelog
prateek3255 Jan 17, 2024
edb8936
Increased size limit of the Multitenancy recipe to 26kb
prateek3255 Jan 17, 2024
542201a
chore: Update CHANGELOG.md
porcellus Jan 17, 2024
3ff8ebf
PR changes
anku255 Jan 18, 2024
6efcdea
Update the method for checking supertokens init
prateek3255 Jan 18, 2024
3c1934d
Update circleci config to run unit tests
anku255 Jan 18, 2024
b85e011
Add tests for thirdParty and emailPassword
prateek3255 Jan 19, 2024
f24e6b1
Add tests for remaining recipes
prateek3255 Jan 19, 2024
c9b1834
Fix copyright year
prateek3255 Jan 19, 2024
f82dee6
Revert old changes and update error messages
prateek3255 Jan 19, 2024
0813340
Move init tests to a separate file
prateek3255 Jan 19, 2024
af92ad7
Update copyright
prateek3255 Jan 19, 2024
e965ca6
Revert version changes
prateek3255 Jan 19, 2024
18b3767
Merge into feat/add-date-provider
prateek3255 Jan 19, 2024
f5ff736
Revert package-lock.json changes
prateek3255 Jan 19, 2024
570978b
Add newline at the end
prateek3255 Jan 19, 2024
beef80f
Merge pull request #104 from supertokens/fix-init-error
rishabhpoddar Jan 19, 2024
4449011
Fix tests
anku255 Jan 20, 2024
57a7149
PR changes
anku255 Jan 22, 2024
8f45e7c
Update Changelog
anku255 Jan 22, 2024
e69e021
PR changes
anku255 Jan 23, 2024
aaca242
PR changes
anku255 Jan 23, 2024
dab532a
PR changes
anku255 Jan 23, 2024
eb170ca
updates dependency
rishabhpoddar Jan 29, 2024
d31fd04
fix: increase size limit
anku255 Jan 29, 2024
9dc4a0b
fix: increase size limit
anku255 Jan 29, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,19 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [unreleased]

## [0.9.0] - 2024-01-18

## Breaking Changes

- The default `DateProvider` implementation relies on `localStorage`. If your environment lacks support for `localStorage`, you must provide custom implementations for either the `DateProvider` or `localStorage`.

### Changes

- `EmailVerificationClaim` now uses `DateProvider` to account for clock skew.
porcellus marked this conversation as resolved.
Show resolved Hide resolved
- Exporting the `DateProvider` from supertokens-website, that both built-in and custom validators can use instead of `Date.now` to get an estimate of the server clock.
- Added the `dateProvider` prop to the configuration that can be used to customize the built-in `DateProvider`.
- Added `getClockSkewInMillis` as an overrideable function to the Session recipe that estimates the time difference between the backend and the client.
porcellus marked this conversation as resolved.
Show resolved Hide resolved

## [0.8.0] - 2023-09-25

### Overview
Expand Down
2 changes: 1 addition & 1 deletion bundle/emailpassword.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion bundle/emailverification.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion bundle/multitenancy.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion bundle/passwordless.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion bundle/supertokens.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion bundle/thirdparty.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion bundle/thirdpartyemailpassword.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion bundle/thirdpartypasswordless.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion bundle/website.js

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions lib/build/dateProvider/index.d.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 24 additions & 0 deletions lib/build/dateProvider/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions lib/build/dateProvider/types.d.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 16 additions & 0 deletions lib/build/dateProvider/types.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 5 additions & 2 deletions lib/build/recipe/emailverification/emailVerificationClaim.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions lib/build/supertokens.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions lib/build/types.d.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion lib/build/version.d.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion lib/build/version.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 16 additions & 0 deletions lib/ts/dateProvider/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/* Copyright (c) 2024, VRAI Labs and/or its affiliates. All rights reserved.
*
* This software is licensed under the Apache License, Version 2.0 (the
* "License") as published by the Apache Software Foundation.
*
* You may not use this file except in compliance with the License. You may
* obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*/

export { DateProviderReference } from "supertokens-website/utils/dateProvider";
16 changes: 16 additions & 0 deletions lib/ts/dateProvider/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/* Copyright (c) 2024, VRAI Labs and/or its affiliates. All rights reserved.
*
* This software is licensed under the Apache License, Version 2.0 (the
* "License") as published by the Apache Software Foundation.
*
* You may not use this file except in compliance with the License. You may
* obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*/

export { DateProviderInput, DateProviderInterface } from "supertokens-website/utils/dateProvider/types";
6 changes: 4 additions & 2 deletions lib/ts/recipe/emailverification/emailVerificationClaim.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { DateProviderReference } from "supertokens-website/utils/dateProvider";
import { SessionClaimValidator, BooleanClaim } from "../session";
import { RecipeInterface } from "./types";

Expand All @@ -21,13 +22,14 @@ export class EmailVerificationClaimClass extends BooleanClaim {
id: this.id,
refresh: this.refresh,
shouldRefresh: (payload, userContext) => {
const DateProvider = DateProviderReference.getReferenceOrThrow().dateProvider;
const value = this.getValueFromPayload(payload, userContext);
return (
value === undefined ||
this.getLastFetchedTime(payload, userContext)! < Date.now() - maxAgeInSeconds * 1000 ||
this.getLastFetchedTime(payload, userContext)! < DateProvider.now() - maxAgeInSeconds * 1000 ||
(value === false &&
this.getLastFetchedTime(payload, userContext)! <
Date.now() - refetchTimeOnFalseInSeconds * 1000)
DateProvider.now() - refetchTimeOnFalseInSeconds * 1000)
);
},
validate: async (payload, userContext) => {
Expand Down
2 changes: 2 additions & 0 deletions lib/ts/supertokens.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import { CookieHandlerReference } from "./cookieHandler";
import { WindowHandlerReference } from "./windowHandler";
import { PostSuperTokensInitCallbacks } from "./postSuperTokensInitCallbacks";
import { Recipe as MultitenancyRecipe } from "./recipe/multitenancy/recipe";
import { DateProviderReference } from "./dateProvider";

export default class SuperTokens {
/*
Expand Down Expand Up @@ -71,6 +72,7 @@ export default class SuperTokens {
static init(config: SuperTokensConfig): void {
CookieHandlerReference.init(config.cookieHandler);
WindowHandlerReference.init(config.windowHandler);
DateProviderReference.init(config.dateProvider);

if (SuperTokens.instance !== undefined) {
console.warn("SuperTokens was already initialized");
Expand Down
12 changes: 12 additions & 0 deletions lib/ts/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import NormalisedURLDomain from "./normalisedURLDomain";
import { NormalisedRecipeConfig } from "./recipe/recipeModule/types";
import { CookieHandlerInput } from "./cookieHandler/types";
import { WindowHandlerInput } from "./windowHandler/types";
import { DateProviderInput } from "./dateProvider/types";

/**
* The configuration object to be passed when calling SuperTokens.init
Expand Down Expand Up @@ -63,6 +64,17 @@ export type SuperTokensConfig = {
* of the SDK may rely on using the sync versions instead.
*/
windowHandler?: WindowHandlerInput;

/**
* Custom provider for SDK timing calculations relative to server time.
*
* The default implementation automatically adjusts for client-server time deviation.
*
* Typically, you won't need to provide these. If provided, the SDK uses
* your implementation instead of the default one.
*/
dateProvider?: DateProviderInput;

/**
* Enabled logging for the SuperTokens SDK. The SDK will log information in different stages.
*/
Expand Down
2 changes: 1 addition & 1 deletion lib/ts/version.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@
* License for the specific language governing permissions and limitations
* under the License.
*/
export const package_version = "0.8.0";
export const package_version = "0.9.0";

export const supported_fdi = ["1.17", "1.18"];
Loading
Loading