UNPKG

@clerk/shared

Version:

Internal package utils used by the Clerk SDKs

71 lines (70 loc) • 2.33 kB
//#region src/internal/clerk-js/nextStep.ts /** * Computes the next step of a sign-in from the fields FAPI sends today. * * @internal */ function getSignInNextStep(signIn) { if (signIn.protectCheck) return { type: "protect" }; if (signIn.isTransferable) return { type: "transfer" }; switch (signIn.status) { case null: case "needs_identifier": return { type: "identifier" }; case "needs_first_factor": return { type: "first_factor", ...verificationState(signIn.firstFactorVerification) }; case "needs_second_factor": return { type: "second_factor", ...verificationState(signIn.secondFactorVerification) }; case "needs_client_trust": return { type: "client_trust" }; case "needs_new_password": return { type: "new_password" }; case "needs_protect_check": return { type: "protect" }; case "complete": return { type: "complete", createdSessionId: signIn.createdSessionId }; default: return { type: "unknown" }; } } /** * Computes the next step of a sign-up from the fields FAPI sends today. * * @internal */ function getSignUpNextStep(signUp) { if (!signUp.id) return { type: "start" }; if (signUp.status === "complete") return { type: "complete", createdSessionId: signUp.createdSessionId }; if (signUp.status !== "missing_requirements") return { type: "unknown" }; if (signUp.protectCheck || signUp.missingFields.includes("protect_check")) return { type: "protect" }; if (signUp.isTransferable) return { type: "transfer" }; if (signUp.missingFields.includes("enterprise_sso")) return { type: "enterprise_sso" }; if (signUp.unverifiedFields.includes("email_address")) return { type: "verify_email", target: signUp.emailAddress, sent: signUp.verifications.emailAddress.nextAction === "needs_attempt" }; if (signUp.unverifiedFields.includes("phone_number")) return { type: "verify_phone", target: signUp.phoneNumber, sent: signUp.verifications.phoneNumber.nextAction === "needs_attempt" }; if (signUp.missingFields.length > 0) return { type: "fields", fields: signUp.missingFields }; return { type: "unknown" }; } function verificationState(verification) { return { strategy: verification.strategy, sent: verification.status === "unverified" }; } //#endregion export { getSignInNextStep, getSignUpNextStep }; //# sourceMappingURL=nextStep.mjs.map