diff --git a/lib/build/recipe/session/sessionClass.d.ts b/lib/build/recipe/session/sessionClass.d.ts index 2e071042d..7553de3e0 100644 --- a/lib/build/recipe/session/sessionClass.d.ts +++ b/lib/build/recipe/session/sessionClass.d.ts @@ -53,5 +53,5 @@ export default class Session implements SessionContainerInterface { setClaimValue(claim: SessionClaim, value: T, userContext?: any): Promise; getClaimValue(claim: SessionClaim, userContext?: any): Promise; removeClaim(claim: SessionClaim, userContext?: any): Promise; - attachToRequestResponse(info: ReqResInfo): void; + attachToRequestResponse(info: ReqResInfo, userContext?: any): void; } diff --git a/lib/build/recipe/session/sessionClass.js b/lib/build/recipe/session/sessionClass.js index a8bd213d5..3f0112a5e 100644 --- a/lib/build/recipe/session/sessionClass.js +++ b/lib/build/recipe/session/sessionClass.js @@ -25,6 +25,7 @@ const utils_1 = require("./utils"); const jwt_1 = require("./jwt"); const logger_1 = require("../../logger"); const constants_1 = require("./constants"); +const utils_2 = require("../../utils"); class Session { constructor( helpers, @@ -177,7 +178,7 @@ class Session { this.helpers.config, this.reqResInfo.transferMethod, this.reqResInfo.req, - {} + utils_2.makeDefaultUserContextFromAPI(this.reqResInfo.req) ); } } else { @@ -265,7 +266,7 @@ class Session { const update = claim.removeFromPayloadByMerge_internal({}, userContext); return this.mergeIntoAccessTokenPayload(update, userContext); } - attachToRequestResponse(info) { + attachToRequestResponse(info, userContext) { this.reqResInfo = info; if (this.accessTokenUpdated) { const { res, transferMethod } = info; @@ -276,7 +277,7 @@ class Session { this.helpers.config, transferMethod, info.req, - {} + userContext !== undefined ? userContext : utils_2.makeDefaultUserContextFromAPI(info.req) ); if (this.refreshToken !== undefined) { cookieAndHeaders_1.setToken( @@ -287,7 +288,7 @@ class Session { this.refreshToken.expiry, transferMethod, info.req, - {} + userContext !== undefined ? userContext : utils_2.makeDefaultUserContextFromAPI(info.req) ); } if (this.antiCsrfToken !== undefined) { diff --git a/lib/build/recipe/session/sessionRequestFunctions.js b/lib/build/recipe/session/sessionRequestFunctions.js index 9b5a3833b..b5fb40344 100644 --- a/lib/build/recipe/session/sessionRequestFunctions.js +++ b/lib/build/recipe/session/sessionRequestFunctions.js @@ -135,16 +135,19 @@ async function getSessionFromRequest({ req, res, config, recipeInterfaceImpl, op // override how the session is attached to the response. // In that scenario the transferMethod passed to attachToRequestResponse likely doesn't // matter, still, we follow the general fallback logic - await session.attachToRequestResponse({ - req, - res, - transferMethod: - requestTransferMethod !== undefined - ? requestTransferMethod - : allowedTransferMethod !== "any" - ? allowedTransferMethod - : "header", - }); + await session.attachToRequestResponse( + { + req, + res, + transferMethod: + requestTransferMethod !== undefined + ? requestTransferMethod + : allowedTransferMethod !== "any" + ? allowedTransferMethod + : "header", + }, + userContext + ); } return session; } @@ -281,11 +284,14 @@ async function refreshSessionInRequest({ res, req, userContext, config, recipeIn cookieAndHeaders_1.clearSession(config, res, transferMethod, req, userContext); } } - await session.attachToRequestResponse({ - req, - res, - transferMethod: requestTransferMethod, - }); + await session.attachToRequestResponse( + { + req, + res, + transferMethod: requestTransferMethod, + }, + userContext + ); logger_1.logDebugMessage("refreshSession: Success!"); // This token isn't handled by getToken/setToken to limit the scope of this legacy/migration code if (req.getCookieValue(LEGACY_ID_REFRESH_TOKEN_COOKIE_NAME) !== undefined) { @@ -389,11 +395,14 @@ async function createNewSessionInRequest({ } } logger_1.logDebugMessage("createNewSession: Cleared old tokens"); - await session.attachToRequestResponse({ - req, - res, - transferMethod: outputTransferMethod, - }); + await session.attachToRequestResponse( + { + req, + res, + transferMethod: outputTransferMethod, + }, + userContext + ); logger_1.logDebugMessage("createNewSession: Attached new tokens to res"); return session; } diff --git a/lib/build/recipe/session/types.d.ts b/lib/build/recipe/session/types.d.ts index 9a49a33cc..ffc71510e 100644 --- a/lib/build/recipe/session/types.d.ts +++ b/lib/build/recipe/session/types.d.ts @@ -313,7 +313,7 @@ export interface SessionContainerInterface { setClaimValue(claim: SessionClaim, value: T, userContext?: any): Promise; getClaimValue(claim: SessionClaim, userContext?: any): Promise; removeClaim(claim: SessionClaim, userContext?: any): Promise; - attachToRequestResponse(reqResInfo: ReqResInfo): Promise | void; + attachToRequestResponse(reqResInfo: ReqResInfo, userContext?: any): Promise | void; } export declare type APIOptions = { recipeImplementation: RecipeInterface; diff --git a/lib/ts/recipe/session/sessionClass.ts b/lib/ts/recipe/session/sessionClass.ts index 4252474e2..a40177f93 100644 --- a/lib/ts/recipe/session/sessionClass.ts +++ b/lib/ts/recipe/session/sessionClass.ts @@ -21,6 +21,7 @@ import { parseJWTWithoutSignatureVerification } from "./jwt"; import { logDebugMessage } from "../../logger"; import RecipeUserId from "../../recipeUserId"; import { protectedProps } from "./constants"; +import { makeDefaultUserContextFromAPI } from "../../utils"; export default class Session implements SessionContainerInterface { constructor( @@ -175,7 +176,7 @@ export default class Session implements SessionContainerInterface { this.helpers.config, this.reqResInfo.transferMethod, this.reqResInfo.req, - {} + makeDefaultUserContextFromAPI(this.reqResInfo.req) ); } } else { @@ -274,7 +275,7 @@ export default class Session implements SessionContainerInterface { return this.mergeIntoAccessTokenPayload(update, userContext); } - attachToRequestResponse(info: ReqResInfo) { + attachToRequestResponse(info: ReqResInfo, userContext?: any) { this.reqResInfo = info; if (this.accessTokenUpdated) { @@ -287,7 +288,7 @@ export default class Session implements SessionContainerInterface { this.helpers.config, transferMethod, info.req, - {} + userContext !== undefined ? userContext : makeDefaultUserContextFromAPI(info.req) ); if (this.refreshToken !== undefined) { setToken( @@ -298,7 +299,7 @@ export default class Session implements SessionContainerInterface { this.refreshToken.expiry, transferMethod, info.req, - {} + userContext !== undefined ? userContext : makeDefaultUserContextFromAPI(info.req) ); } if (this.antiCsrfToken !== undefined) { diff --git a/lib/ts/recipe/session/sessionRequestFunctions.ts b/lib/ts/recipe/session/sessionRequestFunctions.ts index 9727b8f20..0aa25b946 100644 --- a/lib/ts/recipe/session/sessionRequestFunctions.ts +++ b/lib/ts/recipe/session/sessionRequestFunctions.ts @@ -167,16 +167,19 @@ export async function getSessionFromRequest({ // override how the session is attached to the response. // In that scenario the transferMethod passed to attachToRequestResponse likely doesn't // matter, still, we follow the general fallback logic - await session.attachToRequestResponse({ - req, - res, - transferMethod: - requestTransferMethod !== undefined - ? requestTransferMethod - : allowedTransferMethod !== "any" - ? allowedTransferMethod - : "header", - }); + await session.attachToRequestResponse( + { + req, + res, + transferMethod: + requestTransferMethod !== undefined + ? requestTransferMethod + : allowedTransferMethod !== "any" + ? allowedTransferMethod + : "header", + }, + userContext + ); } return session; } @@ -316,11 +319,14 @@ export async function refreshSessionInRequest({ clearSession(config, res, transferMethod, req, userContext); } } - await session.attachToRequestResponse({ - req, - res, - transferMethod: requestTransferMethod, - }); + await session.attachToRequestResponse( + { + req, + res, + transferMethod: requestTransferMethod, + }, + userContext + ); logDebugMessage("refreshSession: Success!"); @@ -443,11 +449,14 @@ export async function createNewSessionInRequest({ } logDebugMessage("createNewSession: Cleared old tokens"); - await session.attachToRequestResponse({ - req, - res, - transferMethod: outputTransferMethod, - }); + await session.attachToRequestResponse( + { + req, + res, + transferMethod: outputTransferMethod, + }, + userContext + ); logDebugMessage("createNewSession: Attached new tokens to res"); return session; diff --git a/lib/ts/recipe/session/types.ts b/lib/ts/recipe/session/types.ts index 746159b27..fc288104b 100644 --- a/lib/ts/recipe/session/types.ts +++ b/lib/ts/recipe/session/types.ts @@ -375,7 +375,7 @@ export interface SessionContainerInterface { setClaimValue(claim: SessionClaim, value: T, userContext?: any): Promise; getClaimValue(claim: SessionClaim, userContext?: any): Promise; removeClaim(claim: SessionClaim, userContext?: any): Promise; - attachToRequestResponse(reqResInfo: ReqResInfo): Promise | void; + attachToRequestResponse(reqResInfo: ReqResInfo, userContext?: any): Promise | void; } export type APIOptions = {