Skip to content

Commit

Permalink
fix: userContext refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
sattvikc committed Oct 4, 2023
1 parent cdb53c2 commit f76d69b
Show file tree
Hide file tree
Showing 18 changed files with 70 additions and 49 deletions.
6 changes: 5 additions & 1 deletion lib/build/recipe/totp/api/createDevice.d.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
// @ts-nocheck
import { APIInterface, APIOptions } from "../types";
export default function createDevice(apiImplementation: APIInterface, options: APIOptions): Promise<boolean>;
export default function createDevice(
apiImplementation: APIInterface,
options: APIOptions,
userContext: any
): Promise<boolean>;
4 changes: 1 addition & 3 deletions lib/build/recipe/totp/api/createDevice.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,8 @@ var __importDefault =
};
Object.defineProperty(exports, "__esModule", { value: true });
const utils_1 = require("../../../utils");
const utils_2 = require("../../../utils");
const session_1 = __importDefault(require("../../session"));
async function createDevice(apiImplementation, options) {
async function createDevice(apiImplementation, options, userContext) {
if (apiImplementation.createDevicePOST === undefined) {
return false;
}
Expand All @@ -35,7 +34,6 @@ async function createDevice(apiImplementation, options) {
overrideGlobalClaimValidators: (_) => [],
});
let { deviceName } = await options.req.getJSONBody();
const userContext = utils_2.makeDefaultUserContextFromAPI(options.req);
let result = await apiImplementation.createDevicePOST({
session,
deviceName,
Expand Down
6 changes: 5 additions & 1 deletion lib/build/recipe/totp/api/listDevices.d.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
// @ts-nocheck
import { APIInterface, APIOptions } from "../types";
export default function listDevices(apiImplementation: APIInterface, options: APIOptions): Promise<boolean>;
export default function listDevices(
apiImplementation: APIInterface,
options: APIOptions,
userContext: any
): Promise<boolean>;
4 changes: 1 addition & 3 deletions lib/build/recipe/totp/api/listDevices.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,12 @@ var __importDefault =
};
Object.defineProperty(exports, "__esModule", { value: true });
const utils_1 = require("../../../utils");
const utils_2 = require("../../../utils");
const session_1 = __importDefault(require("../../session"));
async function listDevices(apiImplementation, options) {
async function listDevices(apiImplementation, options, userContext) {
if (apiImplementation.listDevicesGET === undefined) {
return false;
}
let session = await session_1.default.getSession(options.req, options.res);
const userContext = utils_2.makeDefaultUserContextFromAPI(options.req);
let result = await apiImplementation.listDevicesGET({
session,
options,
Expand Down
6 changes: 5 additions & 1 deletion lib/build/recipe/totp/api/removeDevice.d.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
// @ts-nocheck
import { APIInterface, APIOptions } from "../types";
export default function removeDevice(apiImplementation: APIInterface, options: APIOptions): Promise<boolean>;
export default function removeDevice(
apiImplementation: APIInterface,
options: APIOptions,
userContext: any
): Promise<boolean>;
4 changes: 1 addition & 3 deletions lib/build/recipe/totp/api/removeDevice.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,8 @@ var __importDefault =
Object.defineProperty(exports, "__esModule", { value: true });
const utils_1 = require("../../../utils");
const error_1 = __importDefault(require("../error"));
const utils_2 = require("../../../utils");
const session_1 = __importDefault(require("../../session"));
async function removeDevice(apiImplementation, options) {
async function removeDevice(apiImplementation, options, userContext) {
if (apiImplementation.removeDevicePOST === undefined) {
return false;
}
Expand All @@ -35,7 +34,6 @@ async function removeDevice(apiImplementation, options) {
message: "Please provide deviceName",
});
}
const userContext = utils_2.makeDefaultUserContextFromAPI(options.req);
let result = await apiImplementation.removeDevicePOST({
session,
deviceName,
Expand Down
6 changes: 5 additions & 1 deletion lib/build/recipe/totp/api/verifyCode.d.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
// @ts-nocheck
import { APIInterface, APIOptions } from "../types";
export default function verifyCode(apiImplementation: APIInterface, options: APIOptions): Promise<boolean>;
export default function verifyCode(
apiImplementation: APIInterface,
options: APIOptions,
userContext: any
): Promise<boolean>;
4 changes: 1 addition & 3 deletions lib/build/recipe/totp/api/verifyCode.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,8 @@ var __importDefault =
Object.defineProperty(exports, "__esModule", { value: true });
const utils_1 = require("../../../utils");
const error_1 = __importDefault(require("../error"));
const utils_2 = require("../../../utils");
const session_1 = __importDefault(require("../../session"));
async function verifyCode(apiImplementation, options) {
async function verifyCode(apiImplementation, options, userContext) {
if (apiImplementation.verifyCodePOST === undefined) {
return false;
}
Expand All @@ -37,7 +36,6 @@ async function verifyCode(apiImplementation, options) {
message: "Please provide totp",
});
}
const userContext = utils_2.makeDefaultUserContextFromAPI(options.req);
let result = await apiImplementation.verifyCodePOST({
session,
totp,
Expand Down
6 changes: 5 additions & 1 deletion lib/build/recipe/totp/api/verifyDevice.d.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
// @ts-nocheck
import { APIInterface, APIOptions } from "../types";
export default function verifyDevice(apiImplementation: APIInterface, options: APIOptions): Promise<boolean>;
export default function verifyDevice(
apiImplementation: APIInterface,
options: APIOptions,
userContext: any
): Promise<boolean>;
4 changes: 1 addition & 3 deletions lib/build/recipe/totp/api/verifyDevice.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,8 @@ var __importDefault =
Object.defineProperty(exports, "__esModule", { value: true });
const utils_1 = require("../../../utils");
const error_1 = __importDefault(require("../error"));
const utils_2 = require("../../../utils");
const session_1 = __importDefault(require("../../session"));
async function verifyDevice(apiImplementation, options) {
async function verifyDevice(apiImplementation, options, userContext) {
if (apiImplementation.verifyDevicePOST === undefined) {
return false;
}
Expand All @@ -43,7 +42,6 @@ async function verifyDevice(apiImplementation, options) {
message: "Please provide totp",
});
}
const userContext = utils_2.makeDefaultUserContextFromAPI(options.req);
let result = await apiImplementation.verifyDevicePOST({
session,
deviceName,
Expand Down
3 changes: 2 additions & 1 deletion lib/build/recipe/totp/recipe.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ export default class TotpRecipe extends RecipeModule {
req: BaseRequest,
res: BaseResponse,
_: NormalisedURLPath,
__: HTTPMethod
__: HTTPMethod,
userContext: any
) => Promise<boolean>;
handleError: (err: STError, _: BaseRequest, __: BaseResponse) => Promise<void>;
getAllCORSHeaders: () => string[];
Expand Down
12 changes: 6 additions & 6 deletions lib/build/recipe/totp/recipe.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ class TotpRecipe extends recipeModule_1.default {
},
];
};
this.handleAPIRequest = async (id, ___, req, res, _, __) => {
this.handleAPIRequest = async (id, ___, req, res, _, __, userContext) => {
const options = {
config: this.config,
recipeId: this.getRecipeId(),
Expand All @@ -83,15 +83,15 @@ class TotpRecipe extends recipeModule_1.default {
appInfo: this.getAppInfo(),
};
if (id === constants_1.CREATE_DEVICE_API) {
return await createDevice_1.default(this.apiImpl, options);
return await createDevice_1.default(this.apiImpl, options, userContext);
} else if (id == constants_1.VERIFY_DEVICE_API) {
return await verifyDevice_1.default(this.apiImpl, options);
return await verifyDevice_1.default(this.apiImpl, options, userContext);
} else if (id == constants_1.VERIFY_CODE_API) {
return await verifyCode_1.default(this.apiImpl, options);
return await verifyCode_1.default(this.apiImpl, options, userContext);
} else if (id == constants_1.REMOVE_DEVICE_API) {
return await removeDevice_1.default(this.apiImpl, options);
return await removeDevice_1.default(this.apiImpl, options, userContext);
} else if (id == constants_1.LIST_DEVICE_API) {
return await listDevices_1.default(this.apiImpl, options);
return await listDevices_1.default(this.apiImpl, options, userContext);
}
return false;
};
Expand Down
8 changes: 5 additions & 3 deletions lib/ts/recipe/totp/api/createDevice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,14 @@

import { send200Response } from "../../../utils";
import { APIInterface, APIOptions } from "../types";
import { makeDefaultUserContextFromAPI } from "../../../utils";

import Session from "../../session";

export default async function createDevice(apiImplementation: APIInterface, options: APIOptions): Promise<boolean> {
export default async function createDevice(
apiImplementation: APIInterface,
options: APIOptions,
userContext: any
): Promise<boolean> {
if (apiImplementation.createDevicePOST === undefined) {
return false;
}
Expand All @@ -33,7 +36,6 @@ export default async function createDevice(apiImplementation: APIInterface, opti

let { deviceName } = await options.req.getJSONBody();

const userContext = makeDefaultUserContextFromAPI(options.req);
let result = await apiImplementation.createDevicePOST({
session,
deviceName,
Expand Down
8 changes: 5 additions & 3 deletions lib/ts/recipe/totp/api/listDevices.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,20 @@

import { send200Response } from "../../../utils";
import { APIInterface, APIOptions } from "../types";
import { makeDefaultUserContextFromAPI } from "../../../utils";

import Session from "../../session";

export default async function listDevices(apiImplementation: APIInterface, options: APIOptions): Promise<boolean> {
export default async function listDevices(
apiImplementation: APIInterface,
options: APIOptions,
userContext: any
): Promise<boolean> {
if (apiImplementation.listDevicesGET === undefined) {
return false;
}

let session = await Session.getSession(options.req, options.res);

const userContext = makeDefaultUserContextFromAPI(options.req);
let result = await apiImplementation.listDevicesGET({
session,
options,
Expand Down
8 changes: 5 additions & 3 deletions lib/ts/recipe/totp/api/removeDevice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,14 @@
import { send200Response } from "../../../utils";
import STError from "../error";
import { APIInterface, APIOptions } from "../types";
import { makeDefaultUserContextFromAPI } from "../../../utils";

import Session from "../../session";

export default async function removeDevice(apiImplementation: APIInterface, options: APIOptions): Promise<boolean> {
export default async function removeDevice(
apiImplementation: APIInterface,
options: APIOptions,
userContext: any
): Promise<boolean> {
if (apiImplementation.removeDevicePOST === undefined) {
return false;
}
Expand All @@ -35,7 +38,6 @@ export default async function removeDevice(apiImplementation: APIInterface, opti
});
}

const userContext = makeDefaultUserContextFromAPI(options.req);
let result = await apiImplementation.removeDevicePOST({
session,
deviceName,
Expand Down
9 changes: 5 additions & 4 deletions lib/ts/recipe/totp/api/verifyCode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,14 @@
import { send200Response } from "../../../utils";
import STError from "../error";
import { APIInterface, APIOptions } from "../types";
import { makeDefaultUserContextFromAPI } from "../../../utils";

import Session from "../../session";

export default async function verifyCode(apiImplementation: APIInterface, options: APIOptions): Promise<boolean> {
export default async function verifyCode(
apiImplementation: APIInterface,
options: APIOptions,
userContext: any
): Promise<boolean> {
if (apiImplementation.verifyCodePOST === undefined) {
return false;
}
Expand All @@ -35,8 +38,6 @@ export default async function verifyCode(apiImplementation: APIInterface, option
});
}

const userContext = makeDefaultUserContextFromAPI(options.req);

let result = await apiImplementation.verifyCodePOST({
session,
totp,
Expand Down
8 changes: 5 additions & 3 deletions lib/ts/recipe/totp/api/verifyDevice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,14 @@
import { send200Response } from "../../../utils";
import STError from "../error";
import { APIInterface, APIOptions } from "../types";
import { makeDefaultUserContextFromAPI } from "../../../utils";

import Session from "../../session";

export default async function verifyDevice(apiImplementation: APIInterface, options: APIOptions): Promise<boolean> {
export default async function verifyDevice(
apiImplementation: APIInterface,
options: APIOptions,
userContext: any
): Promise<boolean> {
if (apiImplementation.verifyDevicePOST === undefined) {
return false;
}
Expand All @@ -42,7 +45,6 @@ export default async function verifyDevice(apiImplementation: APIInterface, opti
});
}

const userContext = makeDefaultUserContextFromAPI(options.req);
let result = await apiImplementation.verifyDevicePOST({
session,
deviceName,
Expand Down
13 changes: 7 additions & 6 deletions lib/ts/recipe/totp/recipe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,8 @@ export default class TotpRecipe extends RecipeModule {
req: BaseRequest,
res: BaseResponse,
_: NormalisedURLPath,
__: HTTPMethod
__: HTTPMethod,
userContext: any
): Promise<boolean> => {
const options = {
config: this.config,
Expand All @@ -147,15 +148,15 @@ export default class TotpRecipe extends RecipeModule {
appInfo: this.getAppInfo(),
};
if (id === CREATE_DEVICE_API) {
return await createDeviceAPI(this.apiImpl, options);
return await createDeviceAPI(this.apiImpl, options, userContext);
} else if (id == VERIFY_DEVICE_API) {
return await verifyDeviceAPI(this.apiImpl, options);
return await verifyDeviceAPI(this.apiImpl, options, userContext);
} else if (id == VERIFY_CODE_API) {
return await verifyCodeAPI(this.apiImpl, options);
return await verifyCodeAPI(this.apiImpl, options, userContext);
} else if (id == REMOVE_DEVICE_API) {
return await removeDeviceAPI(this.apiImpl, options);
return await removeDeviceAPI(this.apiImpl, options, userContext);
} else if (id == LIST_DEVICE_API) {
return await listDevicesAPI(this.apiImpl, options);
return await listDevicesAPI(this.apiImpl, options, userContext);
}

return false;
Expand Down

0 comments on commit f76d69b

Please sign in to comment.