Skip to content

Commit

Permalink
Add forceEnrollment option to hide initial back button (#37)
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisfisher authored Jul 8, 2024
1 parent a0cb746 commit 64127fa
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 2 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@authsignal/node",
"version": "1.0.5",
"version": "1.0.6",
"main": "./dist/index.js",
"module": "./dist/index.mjs",
"types": "dist/index.d.ts",
Expand Down
6 changes: 5 additions & 1 deletion src/integrations/auth0.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export interface ExecutePostLoginOptions {
redirectUrl?: string;
custom?: object;
apiBaseUrl?: string;
forceEnrollment?: boolean;
}

// eslint-disable-next-line @typescript-eslint/no-explicit-any
Expand All @@ -27,6 +28,7 @@ export async function handleAuth0ExecutePostLogin(event: any, api: any, options:
redirectUrl = `https://${event.request.hostname}/continue`,
custom = {},
apiBaseUrl = DEFAULT_API_BASE_URL,
forceEnrollment = false,
} = options ?? {};

const sessionMfaMethod = event.authentication?.methods.find(({name}: {name: string}) => name === apiBaseUrl);
Expand All @@ -51,8 +53,10 @@ export async function handleAuth0ExecutePostLogin(event: any, api: any, options:

const {isEnrolled, state, url} = result;

const challengeUrl = forceEnrollment ? `${url}&force_enrollment=true` : url;

if (!isEnrolled || state === UserActionState.CHALLENGE_REQUIRED) {
api.redirect.sendUserTo(url);
api.redirect.sendUserTo(challengeUrl);
} else if (state === UserActionState.BLOCK) {
api.access.deny("Action blocked");
}
Expand Down
1 change: 1 addition & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export interface UserResponse {
isEnrolled: boolean;
email?: string;
phoneNumber?: string;
username?: string;
enrolledVerificationMethods?: VerificationMethod[];
allowedVerificationMethods?: VerificationMethod[];
}
Expand Down

0 comments on commit 64127fa

Please sign in to comment.