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 4 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
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- `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.
- Added `calculateClockSkewInMillis` as an overrideable function to the Session recipe that estimates the time difference between the backend and the client.
- Fix "MultiTenancy not initialized" error being thrown instead of "SuperTokens not initialized" when calling recipe methods directly without initializing SuperTokens first.
porcellus marked this conversation as resolved.
Show resolved Hide resolved

## [0.8.0] - 2023-09-25
Expand Down
2 changes: 1 addition & 1 deletion bundle/emailverification.js

Large diffs are not rendered by default.

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

Large diffs are not rendered by default.

20 changes: 14 additions & 6 deletions lib/build/recipe/emailverification/emailVerificationClaim.js

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

9 changes: 8 additions & 1 deletion lib/ts/recipe/emailverification/emailVerificationClaim.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@ import { DateProviderReference } from "supertokens-website/utils/dateProvider";
import { SessionClaimValidator, BooleanClaim } from "../session";
import { RecipeInterface } from "./types";

function getThresholdAwareDefaultValue(defaultVal: number) {
return Math.max(defaultVal, DateProviderReference.getReferenceOrThrow().dateProvider.getThresholdInSeconds());
anku255 marked this conversation as resolved.
Show resolved Hide resolved
}

/**
* We include "Class" in the class name, because it makes it easier to import/use the right thing (the instance exported by the recipe) instead of this.
* */
Expand All @@ -18,12 +22,15 @@ export class EmailVerificationClaimClass extends BooleanClaim {

this.validators = {
...this.validators,
isVerified: (refetchTimeOnFalseInSeconds = 10, maxAgeInSeconds = 300) => ({
isVerified: (refetchTimeOnFalseInSeconds, maxAgeInSeconds) => ({
rishabhpoddar marked this conversation as resolved.
Show resolved Hide resolved
id: this.id,
refresh: this.refresh,
shouldRefresh: (payload, userContext) => {
const DateProvider = DateProviderReference.getReferenceOrThrow().dateProvider;

maxAgeInSeconds = maxAgeInSeconds ?? getThresholdAwareDefaultValue(10);
rishabhpoddar marked this conversation as resolved.
Show resolved Hide resolved
refetchTimeOnFalseInSeconds = refetchTimeOnFalseInSeconds ?? getThresholdAwareDefaultValue(300);

if (maxAgeInSeconds < DateProvider.getThresholdInSeconds()) {
throw new Error(
`maxAgeInSeconds must be greater than the DateProvider threshold value -> ${DateProvider.getThresholdInSeconds()}`
Expand Down
5 changes: 3 additions & 2 deletions test/with-typescript/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -837,8 +837,8 @@ function getSessionFunctions(original: SessionRecipeInterface): SessionRecipeInt
shouldDoInterceptionBasedOnUrl: function (...input) {
return original.shouldDoInterceptionBasedOnUrl(...input);
},
getClockSkewInMillis: function (input) {
return original.getClockSkewInMillis(input);
calculateClockSkewInMillis: function (input) {
return original.calculateClockSkewInMillis(input);
},
};
}
Expand Down Expand Up @@ -1072,6 +1072,7 @@ const cookieHandlerInput: CookieHandlerInput = (original: CookieHandlerInterface

const dateProviderImplementation: DateProviderInterface = {
getThresholdInSeconds: () => 0,
setThresholdInSeconds: () => {},
getClientClockSkewInMillis: () => 0,
setClientClockSkewInMillis: () => {},
now: () => Date.now(),
Expand Down
Loading