Skip to content

Commit

Permalink
Refactor based on PR review
Browse files Browse the repository at this point in the history
  • Loading branch information
nkshah2 committed Oct 9, 2023
1 parent d40e848 commit 5eed059
Show file tree
Hide file tree
Showing 12 changed files with 26 additions and 28 deletions.
3 changes: 1 addition & 2 deletions lib/build/recipe/dashboard/api/analytics.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ const normalisedURLPath_1 = __importDefault(require("../../../normalisedURLPath"
const version_1 = require("../../../version");
const error_1 = __importDefault(require("../../../error"));
const cross_fetch_1 = __importDefault(require("cross-fetch"));
const utils_1 = require("../../../utils");
async function analyticsPost(_, ___, options, __) {
// If telemetry is disabled, dont send any event
if (!supertokens_1.default.getInstanceOrThrowError().telemetryEnabled) {
Expand Down Expand Up @@ -65,7 +64,7 @@ async function analyticsPost(_, ___, options, __) {
const data = {
websiteDomain: websiteDomain({
request: undefined,
userContext: utils_1.makeDefaultUserContextFromAPI(options.req),
userContext: {},
}).getAsStringDangerous(),
apiDomain: apiDomain.getAsStringDangerous(),
appName,
Expand Down
3 changes: 1 addition & 2 deletions lib/build/recipe/passwordless/recipe.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ const resendCode_1 = __importDefault(require("./api/resendCode"));
const constants_1 = require("./constants");
const emaildelivery_1 = __importDefault(require("../../ingredients/emaildelivery"));
const smsdelivery_1 = __importDefault(require("../../ingredients/smsdelivery"));
const __1 = require("../..");
class Recipe extends recipeModule_1.default {
constructor(recipeId, appInfo, isInServerlessEnv, config, ingredients) {
super(recipeId, appInfo);
Expand Down Expand Up @@ -132,7 +131,7 @@ class Recipe extends recipeModule_1.default {
let magicLink =
appInfo
.getOrigin({
request: __1.getRequestFromUserContext(input.userContext),
request: input.request,
userContext: input.userContext,
})
.getAsStringDangerous() +
Expand Down
6 changes: 5 additions & 1 deletion lib/build/recipe/session/recipe.js
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,11 @@ class SessionRecipe extends recipeModule_1.default {
});
};
this.config = utils_1.validateAndNormaliseUserInput(this, appInfo, config);
logger_1.logDebugMessage("session init: antiCsrf: " + this.config.antiCsrfFunctionOrString);
const antiCsrfToLog =
typeof this.config.antiCsrfFunctionOrString === "string"
? this.config.antiCsrfFunctionOrString
: "function";
logger_1.logDebugMessage("session init: antiCsrf: " + antiCsrfToLog);
logger_1.logDebugMessage("session init: cookieDomain: " + this.config.cookieDomain);
const sameSiteToPrint =
config !== undefined && config.cookieSameSite !== undefined ? config.cookieSameSite : "default function";
Expand Down
4 changes: 2 additions & 2 deletions lib/build/recipe/session/sessionClass.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ class Session {
this.reqResInfo.res,
this.reqResInfo.transferMethod,
this.reqResInfo.req,
userContext
userContext === undefined ? utils_2.makeDefaultUserContextFromAPI(this.reqResInfo.req) : userContext
);
}
}
Expand Down Expand Up @@ -178,7 +178,7 @@ class Session {
this.helpers.config,
this.reqResInfo.transferMethod,
this.reqResInfo.req,
utils_2.makeDefaultUserContextFromAPI(this.reqResInfo.req)
userContext === undefined ? utils_2.makeDefaultUserContextFromAPI(this.reqResInfo.req) : userContext
);
}
} else {
Expand Down
6 changes: 1 addition & 5 deletions lib/build/recipe/session/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,7 @@ export declare type TypeInput = {
userContext: any;
}) => TokenTransferMethod | "any";
errorHandlers?: ErrorHandlers;
antiCsrf?:
| "VIA_TOKEN"
| "VIA_CUSTOM_HEADER"
| "NONE"
| ((input: { request: BaseRequest | undefined; userContext: any }) => "VIA_CUSTOM_HEADER" | "NONE");
antiCsrf?: "VIA_TOKEN" | "VIA_CUSTOM_HEADER" | "NONE";
exposeAccessTokenToFrontendInCookieBasedAuth?: boolean;
override?: {
functions?: (
Expand Down
4 changes: 2 additions & 2 deletions lib/build/recipe/session/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,8 @@ function validateAndNormaliseUserInput(recipeInstance, appInfo, config) {
let protocolOfWebsiteDomain = getURLProtocol(
appInfo
.getOrigin({
request: undefined,
userContext: {},
request: input.request,
userContext: input.userContext,
})
.getAsStringDangerous()
);
Expand Down
3 changes: 1 addition & 2 deletions lib/ts/recipe/dashboard/api/analytics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import NormalisedURLPath from "../../../normalisedURLPath";
import { version as SDKVersion } from "../../../version";
import STError from "../../../error";
import fetch from "cross-fetch";
import { makeDefaultUserContextFromAPI } from "../../../utils";

export type Response = {
status: "OK";
Expand Down Expand Up @@ -76,7 +75,7 @@ export default async function analyticsPost(
const data = {
websiteDomain: websiteDomain({
request: undefined,
userContext: makeDefaultUserContextFromAPI(options.req),
userContext: {},
}).getAsStringDangerous(),
apiDomain: apiDomain.getAsStringDangerous(),
appName,
Expand Down
3 changes: 1 addition & 2 deletions lib/ts/recipe/passwordless/recipe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ import {
import EmailDeliveryIngredient from "../../ingredients/emaildelivery";
import { TypePasswordlessEmailDeliveryInput, TypePasswordlessSmsDeliveryInput } from "./types";
import SmsDeliveryIngredient from "../../ingredients/smsdelivery";
import { getRequestFromUserContext } from "../..";

export default class Recipe extends RecipeModule {
private static instance: Recipe | undefined = undefined;
Expand Down Expand Up @@ -248,7 +247,7 @@ export default class Recipe extends RecipeModule {
let magicLink =
appInfo
.getOrigin({
request: getRequestFromUserContext(input.userContext),
request: input.request,
userContext: input.userContext,
})
.getAsStringDangerous() +
Expand Down
8 changes: 7 additions & 1 deletion lib/ts/recipe/session/recipe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,13 @@ export default class SessionRecipe extends RecipeModule {
constructor(recipeId: string, appInfo: NormalisedAppinfo, isInServerlessEnv: boolean, config?: TypeInput) {
super(recipeId, appInfo);
this.config = validateAndNormaliseUserInput(this, appInfo, config);
logDebugMessage("session init: antiCsrf: " + this.config.antiCsrfFunctionOrString);

const antiCsrfToLog: string =
typeof this.config.antiCsrfFunctionOrString === "string"
? this.config.antiCsrfFunctionOrString
: "function";

logDebugMessage("session init: antiCsrf: " + antiCsrfToLog);
logDebugMessage("session init: cookieDomain: " + this.config.cookieDomain);
const sameSiteToPrint =
config !== undefined && config.cookieSameSite !== undefined ? config.cookieSameSite : "default function";
Expand Down
4 changes: 2 additions & 2 deletions lib/ts/recipe/session/sessionClass.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ export default class Session implements SessionContainerInterface {
this.reqResInfo.res,
this.reqResInfo.transferMethod,
this.reqResInfo.req,
userContext
userContext === undefined ? makeDefaultUserContextFromAPI(this.reqResInfo.req) : userContext
);
}
}
Expand Down Expand Up @@ -176,7 +176,7 @@ export default class Session implements SessionContainerInterface {
this.helpers.config,
this.reqResInfo.transferMethod,
this.reqResInfo.req,
makeDefaultUserContextFromAPI(this.reqResInfo.req)
userContext === undefined ? makeDefaultUserContextFromAPI(this.reqResInfo.req) : userContext
);
}
} else {
Expand Down
6 changes: 1 addition & 5 deletions lib/ts/recipe/session/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,7 @@ export type TypeInput = {
}) => TokenTransferMethod | "any";

errorHandlers?: ErrorHandlers;
antiCsrf?:
| "VIA_TOKEN"
| "VIA_CUSTOM_HEADER"
| "NONE"
| ((input: { request: BaseRequest | undefined; userContext: any }) => "VIA_CUSTOM_HEADER" | "NONE");
antiCsrf?: "VIA_TOKEN" | "VIA_CUSTOM_HEADER" | "NONE";
exposeAccessTokenToFrontendInCookieBasedAuth?: boolean;
override?: {
functions?: (
Expand Down
4 changes: 2 additions & 2 deletions lib/ts/recipe/session/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -145,8 +145,8 @@ export function validateAndNormaliseUserInput(
let protocolOfWebsiteDomain = getURLProtocol(
appInfo
.getOrigin({
request: undefined,
userContext: {},
request: input.request,
userContext: input.userContext,
})
.getAsStringDangerous()
);
Expand Down

0 comments on commit 5eed059

Please sign in to comment.