New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

supertokens-web-js

Package Overview
Dependencies
Maintainers
0
Versions
33
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

supertokens-web-js - npm Package Compare versions

Comparing version 0.13.1 to 0.14.0

bundle/emailpassword.ae01b8ec196ce465b388.js

45

CHANGELOG.md

@@ -10,2 +10,47 @@ # Changelog

## [0.14.0] - 2024-10-07
- Added the OAuth2Provider recipe
### Breaking changes
- Added a new `shouldTryLinkingToSessionUser` flag to sign in/up related function inputs:
- No action is needed if you are not using MFA/session based account linking.
- If you are implementing MFA:
- Plase set this flag to `false` (or leave as undefined) during first factor sign-ins
- Please set this flag to `true` for secondary factors.
- Please forward this flag to the original implementation in any of your overrides.
- Changed functions:
- `EmailPassword.signIn`, `EmailPassword.signUp`: both override and callable functions
- `ThirdParty.getAuthorisationURLWithQueryParamsAndSetState`: both override and callable function
- `Passwordless`:
- Functions overrides: `consumeCode`, `resendCode`, `createCode`, `setLoginAttemptInfo`, `getLoginAttemptInfo`
- Calling `createCode` and `setLoginAttemptInfo` take this flag as an optional input (it defaults to false)
- Changed the default implementation of `getTenantId` to default to the `tenantId` query parameter (if present) then falling back to the public tenant instead of always defaulting to the public tenant
- We now disable session based account linking in the magic link based flow in passwordless by default
- This is to make it function more consistently instead of only working if the link was opened on the same device
- You can override by overriding the `consumeCode` function in the Passwordless Recipe (see in the Migration guide section below for more information)
### Migration guide
#### Session based account linking for magic link based flows
You can re-enable linking by overriding the `consumeCode` function in the passwordless recipe and setting `shouldTryLinkingToSessionUser` to `true`.
```ts
Passwordless.init({
override: {
functions: (original) => {
return {
...original,
consumeCode: async (input) => {
// Please note that this is means that the session is required and will cause an error if it is not present
return original.consumeCode({ ...input, shouldTryLinkingWithSessionUser: true });
},
};
},
},
});
```
## [0.13.1] - 2024-10-08

@@ -12,0 +57,0 @@

@@ -97,2 +97,4 @@ import { RecipeInterface, PreAPIHookContext, PostAPIHookContext, UserInput } from "./types";

*
* @param shouldTryLinkingWithSessionUser (OPTIONAL) Whether the backend should try to link the user to the session user
*
* @param userContext (OPTIONAL) Refer to {@link https://supertokens.com/docs/emailpassword/advanced-customizations/user-context the documentation}

@@ -115,2 +117,3 @@ *

}[];
shouldTryLinkingWithSessionUser?: boolean;
options?: RecipeFunctionOptions;

@@ -143,2 +146,4 @@ userContext?: any;

*
* @param shouldTryLinkingWithSessionUser (OPTIONAL) Whether the backend should try to link the user to the session user
*
* @param userContext (OPTIONAL) Refer to {@link https://supertokens.com/docs/emailpassword/advanced-customizations/user-context the documentation}

@@ -163,2 +168,3 @@ *

}[];
shouldTryLinkingWithSessionUser?: boolean;
options?: RecipeFunctionOptions;

@@ -165,0 +171,0 @@ userContext?: any;

28

lib/build/recipe/emailpassword/index.js

@@ -92,2 +92,4 @@ "use strict";

*
* @param shouldTryLinkingWithSessionUser (OPTIONAL) Whether the backend should try to link the user to the session user
*
* @param userContext (OPTIONAL) Refer to {@link https://supertokens.com/docs/emailpassword/advanced-customizations/user-context the documentation}

@@ -106,7 +108,9 @@ *

RecipeWrapper.signUp = function (input) {
return recipe_1.default
.getInstanceOrThrow()
.recipeImplementation.signUp(
__assign(__assign({}, input), { userContext: (0, utils_1.getNormalisedUserContext)(input.userContext) })
);
return recipe_1.default.getInstanceOrThrow().recipeImplementation.signUp(
__assign(__assign({}, input), {
shouldTryLinkingWithSessionUser:
input === null || input === void 0 ? void 0 : input.shouldTryLinkingWithSessionUser,
userContext: (0, utils_1.getNormalisedUserContext)(input.userContext),
})
);
};

@@ -118,2 +122,4 @@ /**

*
* @param shouldTryLinkingWithSessionUser (OPTIONAL) Whether the backend should try to link the user to the session user
*
* @param userContext (OPTIONAL) Refer to {@link https://supertokens.com/docs/emailpassword/advanced-customizations/user-context the documentation}

@@ -134,7 +140,9 @@ *

RecipeWrapper.signIn = function (input) {
return recipe_1.default
.getInstanceOrThrow()
.recipeImplementation.signIn(
__assign(__assign({}, input), { userContext: (0, utils_1.getNormalisedUserContext)(input.userContext) })
);
return recipe_1.default.getInstanceOrThrow().recipeImplementation.signIn(
__assign(__assign({}, input), {
shouldTryLinkingWithSessionUser:
input === null || input === void 0 ? void 0 : input.shouldTryLinkingWithSessionUser,
userContext: (0, utils_1.getNormalisedUserContext)(input.userContext),
})
);
};

@@ -141,0 +149,0 @@ /**

@@ -298,2 +298,3 @@ "use strict";

var formFields = _a.formFields,
shouldTryLinkingWithSessionUser = _a.shouldTryLinkingWithSessionUser,
options = _a.options,

@@ -319,3 +320,8 @@ userContext = _a.userContext;

"/signup",
{ body: JSON.stringify({ formFields: formFields }) },
{
body: JSON.stringify({
formFields: formFields,
shouldTryLinkingWithSessionUser: shouldTryLinkingWithSessionUser,
}),
},
querier_1.default.preparePreAPIHook({

@@ -370,2 +376,3 @@ recipePreAPIHook: recipeImplInput.preAPIHook,

var formFields = _a.formFields,
shouldTryLinkingWithSessionUser = _a.shouldTryLinkingWithSessionUser,
options = _a.options,

@@ -391,3 +398,8 @@ userContext = _a.userContext;

"/signin",
{ body: JSON.stringify({ formFields: formFields }) },
{
body: JSON.stringify({
formFields: formFields,
shouldTryLinkingWithSessionUser: shouldTryLinkingWithSessionUser,
}),
},
querier_1.default.preparePreAPIHook({

@@ -394,0 +406,0 @@ recipePreAPIHook: recipeImplInput.preAPIHook,

@@ -130,2 +130,4 @@ import {

*
* @param shouldTryLinkingWithSessionUser Whether the backend should try to link the user to the session user
*
* @param userContext Refer to {@link https://supertokens.com/docs/emailpassword/advanced-customizations/user-context the documentation}

@@ -146,2 +148,3 @@ *

}[];
shouldTryLinkingWithSessionUser: boolean | undefined;
options?: RecipeFunctionOptions;

@@ -174,2 +177,4 @@ userContext: any;

*
* @param shouldTryLinkingWithSessionUser Whether the backend should try to link the user to the session user
*
* @param userContext Refer to {@link https://supertokens.com/docs/emailpassword/advanced-customizations/user-context the documentation}

@@ -192,2 +197,3 @@ *

}[];
shouldTryLinkingWithSessionUser: boolean | undefined;
options?: RecipeFunctionOptions;

@@ -194,0 +200,0 @@ userContext: any;

@@ -150,2 +150,3 @@ "use strict";

var querier_1 = require("../../querier");
var utils_1 = require("../../utils");
function getRecipeImplementation(recipeImplInput) {

@@ -155,3 +156,7 @@ var querier = new querier_1.default(recipeImplInput.recipeId, recipeImplInput.appInfo);

getTenantId: function () {
return undefined; // This defaults to the "public" tenant
var queryParam = (0, utils_1.getQueryParams)("tenantId");
if ((queryParam === null || queryParam === void 0 ? void 0 : queryParam.trim()) === "") {
return undefined; // This defaults to the "public" tenant
}
return queryParam;
},

@@ -158,0 +163,0 @@ getLoginMethods: function (_a) {

@@ -20,2 +20,4 @@ import { User } from "../../types";

*
* @param shouldTryLinkingWithSessionUser (OPTIONAL) Whether the backend should try to link the user to the session user
*
* @param userContext (OPTIONAL) Refer to {@link https://supertokens.com/docs/passwordless/advanced-customizations/user-context the documentation}

@@ -33,2 +35,3 @@ *

email: string;
shouldTryLinkingWithSessionUser?: boolean;
userContext?: any;

@@ -39,2 +42,3 @@ options?: RecipeFunctionOptions;

phoneNumber: string;
shouldTryLinkingWithSessionUser?: boolean;
userContext?: any;

@@ -214,2 +218,3 @@ options?: RecipeFunctionOptions;

tenantId?: string | string;
shouldTryLinkingWithSessionUser?: boolean;
preAuthSessionId: string;

@@ -228,2 +233,3 @@ flowType: PasswordlessFlowType;

preAuthSessionId: string;
shouldTryLinkingWithSessionUser?: boolean;
flowType: PasswordlessFlowType;

@@ -230,0 +236,0 @@ } & CustomStateProperties;

@@ -191,2 +191,4 @@ "use strict";

*
* @param shouldTryLinkingWithSessionUser (OPTIONAL) Whether the backend should try to link the user to the session user
*
* @param userContext (OPTIONAL) Refer to {@link https://supertokens.com/docs/passwordless/advanced-customizations/user-context the documentation}

@@ -201,6 +203,7 @@ *

RecipeWrapper.createCode = function (input) {
var _a, _b;
return __awaiter(this, void 0, void 0, function () {
var recipe, recipeImplementation, normalisedUserContext, tenantId, createCodeResponse;
return __generator(this, function (_a) {
switch (_a.label) {
return __generator(this, function (_c) {
switch (_c.label) {
case 0:

@@ -217,11 +220,17 @@ recipe = recipe_2.default.getInstanceOrThrow();

case 1:
tenantId = _a.sent();
tenantId = _c.sent();
return [
4 /*yield*/,
recipeImplementation.createCode(
__assign(__assign({}, input), { userContext: normalisedUserContext })
__assign(__assign({}, input), {
shouldTryLinkingWithSessionUser:
(_a = input.shouldTryLinkingWithSessionUser) !== null && _a !== void 0
? _a
: false,
userContext: normalisedUserContext,
})
),
];
case 2:
createCodeResponse = _a.sent();
createCodeResponse = _c.sent();
if (!(createCodeResponse.status === "OK")) return [3 /*break*/, 4];

@@ -235,2 +244,6 @@ return [

preAuthSessionId: createCodeResponse.preAuthSessionId,
shouldTryLinkingWithSessionUser:
(_b = input.shouldTryLinkingWithSessionUser) !== null && _b !== void 0
? _b
: false,
flowType: createCodeResponse.flowType,

@@ -242,4 +255,4 @@ },

case 3:
_a.sent();
_a.label = 4;
_c.sent();
_c.label = 4;
case 4:

@@ -304,2 +317,6 @@ return [2 /*return*/, createCodeResponse];

previousAttemptInfo === undefined ? "" : previousAttemptInfo.preAuthSessionId,
shouldTryLinkingWithSessionUser:
previousAttemptInfo === null || previousAttemptInfo === void 0
? void 0
: previousAttemptInfo.shouldTryLinkingWithSessionUser,
})

@@ -339,2 +356,3 @@ ),

RecipeWrapper.consumeCode = function (input) {
var _a;
return __awaiter(this, void 0, void 0, function () {

@@ -346,7 +364,9 @@ var recipe,

attemptInfoFromStorage,
shouldTryLinkingWithSessionUser,
shouldTryLinkingWithSessionUser,
linkCode,
tenantId,
preAuthSessionId;
return __generator(this, function (_a) {
switch (_a.label) {
return __generator(this, function (_b) {
switch (_b.label) {
case 0:

@@ -366,10 +386,10 @@ recipe = recipe_2.default.getInstanceOrThrow();

case 1:
attemptInfoFromStorage = _a.sent();
/**
* If attemptInfoFromStorage is undefined then local storage was probably cleared by another tab.
* In this case we use empty strings when calling the API because we want to
* return "RESTART_FLOW_ERROR"
*
* Note: We dont do this for the linkCode flow because that does not depend on local storage.
*/
attemptInfoFromStorage = _b.sent();
shouldTryLinkingWithSessionUser =
(_a =
attemptInfoFromStorage === null || attemptInfoFromStorage === void 0
? void 0
: attemptInfoFromStorage.shouldTryLinkingWithSessionUser) !== null && _a !== void 0
? _a
: false;
additionalParams = {

@@ -380,2 +400,3 @@ userInputCode: input.userInputCode,

attemptInfoFromStorage === undefined ? "" : attemptInfoFromStorage.preAuthSessionId,
shouldTryLinkingWithSessionUser: shouldTryLinkingWithSessionUser,
tenantId:

@@ -388,2 +409,3 @@ attemptInfoFromStorage === null || attemptInfoFromStorage === void 0

case 2:
shouldTryLinkingWithSessionUser = false;
linkCode = recipeImplementation.getLinkCodeFromURL({

@@ -402,4 +424,5 @@ userContext: userContext,

preAuthSessionId: preAuthSessionId,
shouldTryLinkingWithSessionUser: shouldTryLinkingWithSessionUser,
};
_a.label = 3;
_b.label = 3;
case 3:

@@ -550,3 +573,10 @@ return [

recipe.recipeImplementation.setLoginAttemptInfo({
attemptInfo: __assign({ tenantId: tenantId }, input.attemptInfo),
attemptInfo: __assign(
{
tenantId: tenantId,
shouldTryLinkingWithSessionUser:
input.attemptInfo.shouldTryLinkingWithSessionUser,
},
input.attemptInfo
),
userContext: userContext,

@@ -553,0 +583,0 @@ }),

@@ -180,2 +180,3 @@ "use strict";

email: input.email,
shouldTryLinkingWithSessionUser: input.shouldTryLinkingWithSessionUser,
};

@@ -186,2 +187,3 @@ }

phoneNumber: input.phoneNumber,
shouldTryLinkingWithSessionUser: input.shouldTryLinkingWithSessionUser,
};

@@ -232,2 +234,3 @@ }

preAuthSessionId: input.preAuthSessionId,
shouldTryLinkingWithSessionUser: input.shouldTryLinkingWithSessionUser,
};

@@ -277,2 +280,3 @@ return [

preAuthSessionId: input.preAuthSessionId,
shouldTryLinkingWithSessionUser: input.shouldTryLinkingWithSessionUser,
};

@@ -283,2 +287,3 @@ } else {

preAuthSessionId: input.preAuthSessionId,
shouldTryLinkingWithSessionUser: input.shouldTryLinkingWithSessionUser,
};

@@ -285,0 +290,0 @@ }

@@ -48,2 +48,4 @@ import { User } from "../../types";

*
* @param shouldTryLinkingWithSessionUser Whether the backend should try to link the user to the session user when the code is consumed
*
* @param userContext Refer to {@link https://supertokens.com/docs/passwordless/advanced-customizations/user-context the documentation}

@@ -61,2 +63,3 @@ *

email: string;
shouldTryLinkingWithSessionUser: boolean | undefined;
userContext: any;

@@ -67,2 +70,3 @@ options?: RecipeFunctionOptions;

phoneNumber: string;
shouldTryLinkingWithSessionUser: boolean | undefined;
userContext: any;

@@ -92,2 +96,4 @@ options?: RecipeFunctionOptions;

*
* @param shouldTryLinkingWithSessionUser Whether the backend should try to link the user to the session user when the code is consumed
*
* @param userContext Refer to {@link https://supertokens.com/docs/passwordless/advanced-customizations/user-context the documentation}

@@ -107,2 +113,3 @@ *

preAuthSessionId: string;
shouldTryLinkingWithSessionUser: boolean | undefined;
tenantId: string | undefined;

@@ -123,2 +130,4 @@ options?: RecipeFunctionOptions;

*
* @param shouldTryLinkingWithSessionUser Whether the backend should try to link the user to the session user
*
* @param linkCode The code from the URL to use when logging the user in. Ignored if `userInputCode` is provided

@@ -148,2 +157,3 @@ *

preAuthSessionId: string;
shouldTryLinkingWithSessionUser: boolean | undefined;
userContext: any;

@@ -155,2 +165,3 @@ options?: RecipeFunctionOptions;

preAuthSessionId: string;
shouldTryLinkingWithSessionUser: boolean | undefined;
linkCode: string;

@@ -260,2 +271,3 @@ userContext: any;

preAuthSessionId: string;
shouldTryLinkingWithSessionUser?: boolean;
flowType: PasswordlessFlowType;

@@ -274,2 +286,3 @@ } & CustomLoginAttemptInfoProperties)

preAuthSessionId: string;
shouldTryLinkingWithSessionUser: boolean | undefined;
flowType: PasswordlessFlowType;

@@ -276,0 +289,0 @@ } & CustomStateProperties;

@@ -33,2 +33,4 @@ import { User } from "../../types";

*
* @param shouldTryLinkingWithSessionUser (OPTIONAL) Whether the backend should try to link the user to the session user
*
* @param userContext (OPTIONAL) Refer to {@link https://supertokens.com/docs/thirdparty/advanced-customizations/user-context the documentation}

@@ -46,2 +48,3 @@ *

redirectURIOnProviderDashboard?: string;
shouldTryLinkingWithSessionUser?: boolean;
userContext?: any;

@@ -48,0 +51,0 @@ options?: RecipeFunctionOptions;

@@ -208,2 +208,4 @@ "use strict";

*
* @param shouldTryLinkingWithSessionUser (OPTIONAL) Whether the backend should try to link the user to the session user
*
* @param userContext (OPTIONAL) Refer to {@link https://supertokens.com/docs/thirdparty/advanced-customizations/user-context the documentation}

@@ -236,3 +238,9 @@ *

recipe.recipeImplementation.getAuthorisationURLWithQueryParamsAndSetState(
__assign(__assign({ tenantId: tenantId }, input), { userContext: userContext })
__assign(__assign({ tenantId: tenantId }, input), {
shouldTryLinkingWithSessionUser:
input === null || input === void 0
? void 0
: input.shouldTryLinkingWithSessionUser,
userContext: userContext,
})
),

@@ -239,0 +247,0 @@ ];

@@ -252,2 +252,3 @@ "use strict";

input.redirectURIOnProviderDashboard || input.frontendRedirectURI,
shouldTryLinkingWithSessionUser: input.shouldTryLinkingWithSessionUser,
pkceCodeVerifier: urlResponse.pkceCodeVerifier,

@@ -378,2 +379,4 @@ },

},
shouldTryLinkingWithSessionUser:
verifiedState.shouldTryLinkingWithSessionUser,
}),

@@ -380,0 +383,0 @@ },

@@ -42,2 +42,3 @@ import { User } from "../../types";

redirectURIOnProviderDashboard: string;
shouldTryLinkingWithSessionUser?: boolean;
pkceCodeVerifier?: string;

@@ -78,2 +79,4 @@ };

*
* @param shouldTryLinkingWithSessionUser Whether the backend should try to link the user to the session user
*
* @param userContext Refer to {@link https://supertokens.com/docs/thirdparty/advanced-customizations/user-context the documentation}

@@ -91,2 +94,3 @@ *

tenantId: string | undefined;
shouldTryLinkingWithSessionUser: boolean | undefined;
redirectURIOnProviderDashboard?: string;

@@ -93,0 +97,0 @@ userContext: any;

@@ -88,3 +88,3 @@ "use strict";

if (Recipe.instance === undefined) {
var error = "No instance of Multitenancy found. Make sure to call the Multitenancy.init method.";
var error = "No instance of TOTP found. Make sure to call the TOTP.init method.";
error = (0, utils_2.checkForSSRErrorAndAppendIfNeeded)(error);

@@ -91,0 +91,0 @@ throw Error(error);

@@ -86,2 +86,5 @@ "use strict";

}
// We reset the multitenancy recipe here because we are auto-initializing it
// and we should always be resetting it when we reset the SDK
recipe_1.Recipe.reset();
SuperTokens.instance = undefined;

@@ -88,0 +91,0 @@ return;

@@ -1,2 +0,2 @@

export declare const package_version = "0.13.1";
export declare const package_version = "0.14.0";
export declare const supported_fdi: string[];

@@ -18,3 +18,3 @@ "use strict";

*/
exports.package_version = "0.13.1";
exports.supported_fdi = ["2.0", "3.0"];
exports.package_version = "0.14.0";
exports.supported_fdi = ["3.1", "4.0"];
{
"name": "supertokens-web-js",
"version": "0.13.1",
"version": "0.14.0",
"description": "SuperTokens SDK for vanilla JS for all recipes",

@@ -43,3 +43,3 @@ "main": "./index.js",

"supertokens-js-override": "0.0.4",
"supertokens-website": "^20.0.1"
"supertokens-website": "^20.1.5"
},

@@ -69,11 +69,11 @@ "devDependencies": {

"path": "lib/build/index.js",
"limit": "27.5kb"
"limit": "28kb"
},
{
"path": "recipe/emailverification/index.js",
"limit": "28kb"
"limit": "29kb"
},
{
"path": "recipe/emailpassword/index.js",
"limit": "28kb"
"limit": "29kb"
},

@@ -90,21 +90,25 @@ {

"path": "recipe/passwordless/index.js",
"limit": "29kb"
"limit": "30kb"
},
{
"path": "recipe/userroles/index.js",
"limit": "25kb"
"limit": "26kb"
},
{
"path": "recipe/multitenancy/index.js",
"limit": "27kb"
"limit": "28kb"
},
{
"path": "recipe/multifactorauth/index.js",
"limit": "27.5kb"
"limit": "28kb"
},
{
"path": "recipe/totp/index.js",
"limit": "27kb"
"limit": "28kb"
},
{
"path": "recipe/oauth2provider/index.js",
"limit": "28kb"
}
]
}

@@ -67,2 +67,7 @@ var webpack = require("webpack");

},
supertokensOAuth2Provider: {
import: APP_DIR + "/lib/build/recipe/oauth2provider/index.js",
filename: "oauth2provider.[contenthash].js",
dependOn: "supertokensWebsite",
},
/**

@@ -69,0 +74,0 @@ * The import path is /utils/dateProvider/index.js instead of /lib/build/dateProvider/index.js because the supertokens.js also imports

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc