Skip to content

Commit

Permalink
feat: update to match BE changes
Browse files Browse the repository at this point in the history
  • Loading branch information
porcellus committed Jan 2, 2024
1 parent 8bdfd64 commit ef449b7
Show file tree
Hide file tree
Showing 11 changed files with 64 additions and 67 deletions.
2 changes: 1 addition & 1 deletion bundle/multifactorauth.js

Large diffs are not rendered by default.

12 changes: 6 additions & 6 deletions lib/build/recipe/multifactorauth/index.d.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 15 additions & 7 deletions lib/build/recipe/multifactorauth/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion lib/build/recipe/multifactorauth/multiFactorAuthClaim.d.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 6 additions & 7 deletions lib/build/recipe/multifactorauth/multiFactorAuthClaim.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 2 additions & 3 deletions lib/build/recipe/multifactorauth/recipeImplementation.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 6 additions & 10 deletions lib/build/recipe/multifactorauth/types.d.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 7 additions & 6 deletions lib/ts/recipe/multifactorauth/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import { MultiFactorAuthClaimClass } from "./multiFactorAuthClaim";
import Recipe from "./recipe";
import { PreAndPostAPIHookAction, PreAPIHookContext, PostAPIHookContext, RecipeInterface, UserInput } from "./types";
import { RecipeFunctionOptions } from "../recipeModule/types";
import { getNormalisedUserContext } from "../../utils";

export default class RecipeWrapper {
static init(config?: UserInput) {
Expand All @@ -32,23 +33,23 @@ export default class RecipeWrapper {
*
* @returns `{ status: "OK", ...}` if successful
*/
static getMFAInfo(input: { options?: RecipeFunctionOptions; userContext?: any }) {
return Recipe.getInstanceOrThrow().recipeImplementation.getMFAInfo({
options: input.options,
userContext: input.userContext ?? {},
static resyncSessionAndFetchMFAInfo(input?: { options?: RecipeFunctionOptions; userContext?: any }) {
return Recipe.getInstanceOrThrow().recipeImplementation.resyncSessionAndFetchMFAInfo({
options: input?.options ?? {},
userContext: getNormalisedUserContext(input?.userContext),
});
}

static MultiFactorAuthClaim = Recipe.MultiFactorAuthClaim;
}

const init = RecipeWrapper.init;
const getMFAInfo = RecipeWrapper.getMFAInfo;
const resyncSessionAndFetchMFAInfo = RecipeWrapper.resyncSessionAndFetchMFAInfo;
const MultiFactorAuthClaim = RecipeWrapper.MultiFactorAuthClaim;

export {
init,
getMFAInfo,
resyncSessionAndFetchMFAInfo,
RecipeInterface,
PreAPIHookContext,
PostAPIHookContext,
Expand Down
16 changes: 8 additions & 8 deletions lib/ts/recipe/multifactorauth/multiFactorAuthClaim.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ export class MultiFactorAuthClaimClass implements SessionClaim<MFAClaimValue> {
},
};
}
if (val.n.length === 0) {

if (val.v) {
return {
isValid: true,
};
Expand All @@ -41,7 +42,6 @@ export class MultiFactorAuthClaimClass implements SessionClaim<MFAClaimValue> {
isValid: false,
reason: {
message: "not all required factors have been completed",
nextFactorOptions: val?.n,
},
};
},
Expand Down Expand Up @@ -81,16 +81,16 @@ export class MultiFactorAuthClaimClass implements SessionClaim<MFAClaimValue> {
},
};
}
} else if (typeof req === "object" && "allOf" in req) {
const res = req.allOf
} else if (typeof req === "object" && "allOfInAnyOrder" in req) {
const res = req.allOfInAnyOrder
.map((r) => checkFactorRequirement(r, completedFactors))
.filter((v) => v.isValid === false);
if (res.length !== 0) {
return {
isValid: false,
reason: {
message: "Some factor checkers failed in the list",
allOf: req.allOf,
allOfInAnyOrder: req.allOfInAnyOrder,
failures: res,
},
};
Expand Down Expand Up @@ -118,17 +118,17 @@ export class MultiFactorAuthClaimClass implements SessionClaim<MFAClaimValue> {
}

async refresh(userContext: any): Promise<void> {
await this.getRecipeImpl().getMFAInfo(userContext);
await this.getRecipeImpl().resyncSessionAndFetchMFAInfo(userContext);
}

getValueFromPayload(payload: any, _userContext?: any): { c: Record<string, number>; n: string[] } | undefined {
getValueFromPayload(payload: any, _userContext?: any): { c: Record<string, number>; v: boolean } | undefined {
if (payload[this.id] === undefined) {
return undefined;
}

return {
c: payload[this.id].c,
n: payload[this.id].n,
v: payload[this.id].v,
};
}

Expand Down
13 changes: 6 additions & 7 deletions lib/ts/recipe/multifactorauth/recipeImplementation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
*/

import Querier from "../../querier";
import { MFAFactorInfo, RecipeInterface } from "./types";
import { RecipeInterface } from "./types";
import { RecipeImplementationInput } from "../recipeModule/types";
import { PreAndPostAPIHookAction } from "./types";

Expand All @@ -24,17 +24,16 @@ export default function getRecipeImplementation(
const querier = new Querier(recipeImplInput.recipeId, recipeImplInput.appInfo);

return {
getMFAInfo: async function ({ options, userContext }) {
const { jsonBody, fetchResponse } = await querier.get<{
resyncSessionAndFetchMFAInfo: async function ({ options, userContext }) {
const { jsonBody, fetchResponse } = await querier.put<{
status: "OK";
factors: MFAFactorInfo;
email?: string;
phoneNumber?: string;
nextFactors: string[];
emails: Record<string, string[] | undefined>;
phoneNumbers: Record<string, string[] | undefined>;
}>(
undefined,
"/mfa/info",
{},
undefined,
Querier.preparePreAPIHook({
recipePreAPIHook: recipeImplInput.preAPIHook,
action: "GET_MFA_INFO",
Expand Down
17 changes: 6 additions & 11 deletions lib/ts/recipe/multifactorauth/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,17 +49,12 @@ export type NormalisedInputType = AuthRecipeNormalisedInputType<PreAndPostAPIHoo
};
};

export type MFAFactorInfo = {
isAlreadySetup: string[];
isAllowedToSetup: string[];
};

export type RecipeInterface = {
getMFAInfo: (input: { options?: RecipeFunctionOptions; userContext: any }) => Promise<{
resyncSessionAndFetchMFAInfo: (input: { options?: RecipeFunctionOptions; userContext: any }) => Promise<{
status: "OK";
factors: MFAFactorInfo;
email?: string;
phoneNumber?: string;
nextFactors: string[];
emails: Record<string, string[] | undefined>;
phoneNumbers: Record<string, string[] | undefined>;
fetchResponse: Response;
}>;
};
Expand All @@ -71,12 +66,12 @@ export type MFARequirementList = (
oneOf: MFARequirement[];
}
| {
allOf: MFARequirement[];
allOfInAnyOrder: MFARequirement[];
}
| MFARequirement
)[];

export type MFAClaimValue = {
c: Record<string, number>;
n: string[];
v: boolean;
};

0 comments on commit ef449b7

Please sign in to comment.