From 814d865ad3917a0c2aa0a591c3cd1dcb052cfcac Mon Sep 17 00:00:00 2001 From: Nemi Shah Date: Mon, 9 Oct 2023 11:13:37 +0530 Subject: [PATCH] Refactor getPasswordResetLink --- lib/build/recipe/emailpassword/api/implementation.js | 1 + lib/build/recipe/emailpassword/index.js | 1 + lib/build/recipe/emailpassword/utils.d.ts | 2 ++ lib/build/recipe/emailpassword/utils.js | 3 +-- lib/build/recipe/thirdpartyemailpassword/index.js | 1 + lib/ts/recipe/emailpassword/api/implementation.ts | 1 + lib/ts/recipe/emailpassword/index.ts | 3 ++- lib/ts/recipe/emailpassword/utils.ts | 5 +++-- lib/ts/recipe/thirdpartyemailpassword/index.ts | 3 ++- 9 files changed, 14 insertions(+), 6 deletions(-) diff --git a/lib/build/recipe/emailpassword/api/implementation.js b/lib/build/recipe/emailpassword/api/implementation.js index 553dcbb13..284b26954 100644 --- a/lib/build/recipe/emailpassword/api/implementation.js +++ b/lib/build/recipe/emailpassword/api/implementation.js @@ -63,6 +63,7 @@ function getAPIImplementation() { token: response.token, recipeId: options.recipeId, tenantId, + request: options.req, userContext, }); logger_1.logDebugMessage(`Sending password reset email to ${email}`); diff --git a/lib/build/recipe/emailpassword/index.js b/lib/build/recipe/emailpassword/index.js index a2735886c..5c665fda5 100644 --- a/lib/build/recipe/emailpassword/index.js +++ b/lib/build/recipe/emailpassword/index.js @@ -107,6 +107,7 @@ class Wrapper { recipeId: recipeInstance.getRecipeId(), token: token.token, tenantId: tenantId === undefined ? constants_1.DEFAULT_TENANT_ID : tenantId, + request: __1.getRequestFromUserContext(userContext), userContext, }), }; diff --git a/lib/build/recipe/emailpassword/utils.d.ts b/lib/build/recipe/emailpassword/utils.d.ts index ea4f1f8a9..f9ef8d5dc 100644 --- a/lib/build/recipe/emailpassword/utils.d.ts +++ b/lib/build/recipe/emailpassword/utils.d.ts @@ -2,6 +2,7 @@ import Recipe from "./recipe"; import { TypeInput, TypeNormalisedInput, NormalisedFormField, TypeInputFormField } from "./types"; import { NormalisedAppinfo } from "../../types"; +import { BaseRequest } from "../../framework"; export declare function validateAndNormaliseUserInput( recipeInstance: Recipe, appInfo: NormalisedAppinfo, @@ -26,5 +27,6 @@ export declare function getPasswordResetLink(input: { token: string; recipeId: string; tenantId: string; + request: BaseRequest | undefined; userContext: any; }): string; diff --git a/lib/build/recipe/emailpassword/utils.js b/lib/build/recipe/emailpassword/utils.js index b52124d85..f2518e26e 100644 --- a/lib/build/recipe/emailpassword/utils.js +++ b/lib/build/recipe/emailpassword/utils.js @@ -22,7 +22,6 @@ Object.defineProperty(exports, "__esModule", { value: true }); exports.getPasswordResetLink = exports.defaultEmailValidator = exports.defaultPasswordValidator = exports.normaliseSignUpFormFields = exports.validateAndNormaliseUserInput = void 0; const constants_1 = require("./constants"); const backwardCompatibility_1 = __importDefault(require("./emaildelivery/services/backwardCompatibility")); -const __1 = require("../.."); function validateAndNormaliseUserInput(recipeInstance, appInfo, config) { let signUpFeature = validateAndNormaliseSignupConfig( recipeInstance, @@ -216,7 +215,7 @@ function getPasswordResetLink(input) { return ( input.appInfo .getOrigin({ - request: __1.getRequestFromUserContext(input.userContext), + request: input.request, userContext: input.userContext, }) .getAsStringDangerous() + diff --git a/lib/build/recipe/thirdpartyemailpassword/index.js b/lib/build/recipe/thirdpartyemailpassword/index.js index 7e217c0a7..72f6ea4f8 100644 --- a/lib/build/recipe/thirdpartyemailpassword/index.js +++ b/lib/build/recipe/thirdpartyemailpassword/index.js @@ -121,6 +121,7 @@ class Wrapper { recipeId: recipeInstance.getRecipeId(), token: token.token, tenantId, + request: __1.getRequestFromUserContext(userContext), userContext, }), }; diff --git a/lib/ts/recipe/emailpassword/api/implementation.ts b/lib/ts/recipe/emailpassword/api/implementation.ts index 074754b56..0fa0e069c 100644 --- a/lib/ts/recipe/emailpassword/api/implementation.ts +++ b/lib/ts/recipe/emailpassword/api/implementation.ts @@ -106,6 +106,7 @@ export default function getAPIImplementation(): APIInterface { token: response.token, recipeId: options.recipeId, tenantId, + request: options.req, userContext, }); diff --git a/lib/ts/recipe/emailpassword/index.ts b/lib/ts/recipe/emailpassword/index.ts index af0bd1321..ac4de3649 100644 --- a/lib/ts/recipe/emailpassword/index.ts +++ b/lib/ts/recipe/emailpassword/index.ts @@ -19,7 +19,7 @@ import { RecipeInterface, APIOptions, APIInterface, TypeEmailPasswordEmailDelive import RecipeUserId from "../../recipeUserId"; import { DEFAULT_TENANT_ID } from "../multitenancy/constants"; import { getPasswordResetLink } from "./utils"; -import { getUser } from "../.."; +import { getRequestFromUserContext, getUser } from "../.."; export default class Wrapper { static init = Recipe.init; @@ -123,6 +123,7 @@ export default class Wrapper { recipeId: recipeInstance.getRecipeId(), token: token.token, tenantId: tenantId === undefined ? DEFAULT_TENANT_ID : tenantId, + request: getRequestFromUserContext(userContext), userContext, }), }; diff --git a/lib/ts/recipe/emailpassword/utils.ts b/lib/ts/recipe/emailpassword/utils.ts index ecd791d21..9a31c7348 100644 --- a/lib/ts/recipe/emailpassword/utils.ts +++ b/lib/ts/recipe/emailpassword/utils.ts @@ -28,7 +28,7 @@ import { NormalisedAppinfo } from "../../types"; import { FORM_FIELD_EMAIL_ID, FORM_FIELD_PASSWORD_ID } from "./constants"; import { RecipeInterface, APIInterface } from "./types"; import BackwardCompatibilityService from "./emaildelivery/services/backwardCompatibility"; -import { getRequestFromUserContext } from "../.."; +import { BaseRequest } from "../../framework"; export function validateAndNormaliseUserInput( recipeInstance: Recipe, @@ -254,12 +254,13 @@ export function getPasswordResetLink(input: { token: string; recipeId: string; tenantId: string; + request: BaseRequest | undefined; userContext: any; }): string { return ( input.appInfo .getOrigin({ - request: getRequestFromUserContext(input.userContext), + request: input.request, userContext: input.userContext, }) .getAsStringDangerous() + diff --git a/lib/ts/recipe/thirdpartyemailpassword/index.ts b/lib/ts/recipe/thirdpartyemailpassword/index.ts index 9a1828f88..04d072df6 100644 --- a/lib/ts/recipe/thirdpartyemailpassword/index.ts +++ b/lib/ts/recipe/thirdpartyemailpassword/index.ts @@ -21,7 +21,7 @@ import { TypeEmailPasswordEmailDeliveryInput } from "../emailpassword/types"; import RecipeUserId from "../../recipeUserId"; import { DEFAULT_TENANT_ID } from "../multitenancy/constants"; import { getPasswordResetLink } from "../emailpassword/utils"; -import { getUser } from "../.."; +import { getRequestFromUserContext, getUser } from "../.."; export default class Wrapper { static init = Recipe.init; @@ -146,6 +146,7 @@ export default class Wrapper { recipeId: recipeInstance.getRecipeId(), token: token.token, tenantId, + request: getRequestFromUserContext(userContext), userContext, }), };