UNPKG

@better-auth-ui/core

Version:

Authentication components and data utilities for [Better Auth](https://better-auth.com), available for React and Solid.

262 lines (261 loc) 6.96 kB
import { t as e } from "../../auth-query-keys-B_bcsA3s.js"; import { t } from "../../create-auth-plugin-BXWyolC8.js"; //#region src/plugins/two-factor/two-factor-mutation-keys.ts var n = { enable: [ "auth", "twoFactor", "enable" ], disable: [ "auth", "twoFactor", "disable" ], getTotpUri: [ "auth", "twoFactor", "getTotpUri" ], generateBackupCodes: [ "auth", "twoFactor", "generateBackupCodes" ], sendOtp: [ "auth", "twoFactor", "sendOtp" ], verifyTotp: [ "auth", "signIn", "twoFactor", "verifyTotp" ], verifyOtp: [ "auth", "signIn", "twoFactor", "verifyOtp" ], verifyBackupCode: [ "auth", "signIn", "twoFactor", "verifyBackupCode" ] }; //#endregion //#region src/plugins/two-factor/disable-two-factor-mutation.ts function r(t) { return { mutationKey: n.disable, mutationFn: (e) => t.twoFactor.disable({ ...e, fetchOptions: { ...e?.fetchOptions, throw: !0 } }), meta: { awaits: [e.session] } }; } //#endregion //#region src/plugins/two-factor/enable-two-factor-mutation.ts function i(t) { return { mutationKey: n.enable, mutationFn: (e) => t.twoFactor.enable({ ...e, fetchOptions: { ...e?.fetchOptions, throw: !0 } }), meta: { awaits: [e.session] } }; } //#endregion //#region src/plugins/two-factor/generate-backup-codes-mutation.ts function a(e) { return { mutationKey: n.generateBackupCodes, mutationFn: (t) => e.twoFactor.generateBackupCodes({ ...t, fetchOptions: { ...t?.fetchOptions, throw: !0 } }) }; } //#endregion //#region src/plugins/two-factor/get-totp-uri-mutation.ts function o(e) { return { mutationKey: n.getTotpUri, mutationFn: (t) => e.twoFactor.getTotpUri({ ...t, fetchOptions: { ...t?.fetchOptions, throw: !0 } }) }; } //#endregion //#region src/plugins/two-factor/send-two-factor-otp-mutation.ts function s(e) { return { mutationKey: n.sendOtp, mutationFn: (t) => e.twoFactor.sendOtp({ ...t ?? {}, fetchOptions: { ...t?.fetchOptions, throw: !0 } }) }; } //#endregion //#region src/plugins/two-factor/two-factor-challenge.ts var c = ["totp", "otp"], l = "better-auth-ui.two-factor-methods"; function u(e) { return typeof e == "object" && !!e && e.twoFactorRedirect === !0; } function d(e) { return Array.isArray(e) ? c.filter((t) => e.includes(t)) : []; } function f(e) { if (!(typeof sessionStorage > "u")) try { sessionStorage.setItem(l, JSON.stringify(d(e))); } catch {} } function p() { if (typeof sessionStorage > "u") return c; try { let e = sessionStorage.getItem(l); if (!e) return c; let t = d(JSON.parse(e)); return t.length ? t : c; } catch { return c; } } function m() { if (!(typeof sessionStorage > "u")) try { sessionStorage.removeItem(l); } catch {} } //#endregion //#region src/plugins/two-factor/two-factor-localization.ts var h = { twoFactor: "Two-Factor Authentication", twoFactorDescription: "Add a second step to sign-in so a stolen password isn't enough", enableTwoFactor: "Enable two-factor", disableTwoFactor: "Disable two-factor", twoFactorEnabled: "Two-factor authentication is on", twoFactorDisabled: "Two-factor authentication is off", passwordConfirmation: "Enter your password to continue", chooseEnrollmentMethod: "Choose how you want to verify future sign-ins", authenticatorApp: "Authenticator app", authenticatorAppDescription: "Use a rotating code from an authenticator app", deliveredCode: "Email or SMS code", deliveredCodeDescription: "Receive a new code each time you sign in", scanQrCode: "Scan this with your authenticator app", setupKey: "Can't scan? Enter this setup key instead", setupKeyCopied: "Setup key copied", setupKeyCopyFailed: "Couldn't copy the setup key. Select and copy it manually.", authenticatorCode: "Authenticator code", authenticatorCodeDescription: "Enter the code from your authenticator app", emailedCode: "Emailed code", emailedCodeDescription: "We emailed you a code. Enter it to finish signing in", sendEmailCode: "Email me a code", backupCode: "Backup code", backupCodeDescription: "Enter one of the backup codes you saved", backupCodes: "Backup codes", backupCodesForWebsite: "Backup codes for {{website}}", backupCodesDescription: "Save these somewhere safe. Each code works once if you lose your authenticator.", backupCodesCopied: "Backup codes copied", backupCodesCopyFailed: "Couldn't copy the backup codes. Select and copy them manually.", downloadBackupCodes: "Download .txt", printBackupCodes: "Print", regenerateBackupCodes: "Regenerate backup codes", backupCodesRegenerated: "New backup codes generated. The old ones no longer work.", useAuthenticator: "Use your authenticator app", useEmailedCode: "Use an emailed code", useBackupCode: "Use a backup code", trustDevice: "Trust this device", trustDeviceDescription: "Skip the second step on this device from now on", verify: "Verify", codeLengthMismatch: "Enter the {{length}}-digit code", backToSignIn: "Back to sign in", done: "Done" }, g = 6; function _(e) { return e === void 0 || !Number.isFinite(e) ? g : Math.max(1, Math.floor(e)); } function v(e) { let t = d(e); return t.length ? t : ["totp"]; } var y = t("twoFactor", (e = {}) => ({ localization: { ...h, ...e.localization }, codeLength: _(e.codeLength), backupCodes: e.backupCodes ?? !0, trustDevice: e.trustDevice ?? !0, allowPasswordless: e.allowPasswordless ?? !1, enrollmentMethods: v(e.enrollmentMethods), viewPaths: { auth: { twoFactor: e.path ?? "two-factor" } } })); //#endregion //#region src/plugins/two-factor/verify-backup-code-mutation.ts function b(t) { return { mutationKey: n.verifyBackupCode, mutationFn: (e) => t.twoFactor.verifyBackupCode({ ...e, fetchOptions: { ...e?.fetchOptions, throw: !0 } }), meta: { awaits: [e.session] } }; } //#endregion //#region src/plugins/two-factor/verify-totp-mutation.ts function x(t) { return { mutationKey: n.verifyTotp, mutationFn: (e) => t.twoFactor.verifyTotp({ ...e, fetchOptions: { ...e?.fetchOptions, throw: !0 } }), meta: { awaits: [e.session] } }; } //#endregion //#region src/plugins/two-factor/verify-two-factor-otp-mutation.ts function S(t) { return { mutationKey: n.verifyOtp, mutationFn: (e) => t.twoFactor.verifyOtp({ ...e, fetchOptions: { ...e?.fetchOptions, throw: !0 } }), meta: { awaits: [e.session] } }; } //#endregion export { l as TWO_FACTOR_METHODS_STORAGE_KEY, m as clearTwoFactorMethods, r as disableTwoFactorOptions, i as enableTwoFactorOptions, a as generateBackupCodesOptions, o as getTotpUriOptions, u as isTwoFactorRedirect, d as parseTwoFactorMethods, p as readTwoFactorMethods, s as sendTwoFactorOtpOptions, f as storeTwoFactorMethods, h as twoFactorLocalization, n as twoFactorMutationKeys, y as twoFactorPlugin, b as verifyBackupCodeOptions, x as verifyTotpOptions, S as verifyTwoFactorOtpOptions };