Initial commit of eigent-main

This commit is contained in:
puzhen 2025-08-12 01:16:39 +02:00
commit 723df5a03e
1144 changed files with 103478 additions and 0 deletions

View file

@ -0,0 +1,46 @@
"use strict";
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
// src/components-page/account-settings/email-and-auth/email-and-auth-page.tsx
var email_and_auth_page_exports = {};
__export(email_and_auth_page_exports, {
EmailsAndAuthPage: () => EmailsAndAuthPage
});
module.exports = __toCommonJS(email_and_auth_page_exports);
var import_page_layout = require("../page-layout");
var import_emails_section = require("./emails-section");
var import_mfa_section = require("./mfa-section");
var import_otp_section = require("./otp-section");
var import_passkey_section = require("./passkey-section");
var import_password_section = require("./password-section");
var import_jsx_runtime = require("react/jsx-runtime");
function EmailsAndAuthPage() {
return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_page_layout.PageLayout, { children: [
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_emails_section.EmailsSection, {}),
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_password_section.PasswordSection, {}),
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_passkey_section.PasskeySection, {}),
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_otp_section.OtpSection, {}),
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_mfa_section.MfaSection, {})
] });
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
EmailsAndAuthPage
});
//# sourceMappingURL=email-and-auth-page.js.map

View file

@ -0,0 +1 @@
{"version":3,"sources":["../../../../src/components-page/account-settings/email-and-auth/email-and-auth-page.tsx"],"sourcesContent":["\n//===========================================\n// THIS FILE IS AUTO-GENERATED FROM TEMPLATE. DO NOT EDIT IT DIRECTLY\n//===========================================\nimport { PageLayout } from \"../page-layout\";\nimport { EmailsSection } from \"./emails-section\";\nimport { MfaSection } from \"./mfa-section\";\nimport { OtpSection } from \"./otp-section\";\nimport { PasskeySection } from \"./passkey-section\";\nimport { PasswordSection } from \"./password-section\";\n\nexport function EmailsAndAuthPage() {\n return (\n <PageLayout>\n <EmailsSection/>\n <PasswordSection />\n <PasskeySection />\n <OtpSection />\n <MfaSection />\n </PageLayout>\n );\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAIA,yBAA2B;AAC3B,4BAA8B;AAC9B,yBAA2B;AAC3B,yBAA2B;AAC3B,6BAA+B;AAC/B,8BAAgC;AAI5B;AAFG,SAAS,oBAAoB;AAClC,SACE,6CAAC,iCACC;AAAA,gDAAC,uCAAa;AAAA,IACd,4CAAC,2CAAgB;AAAA,IACjB,4CAAC,yCAAe;AAAA,IAChB,4CAAC,iCAAW;AAAA,IACZ,4CAAC,iCAAW;AAAA,KACd;AAEJ;","names":[]}

View file

@ -0,0 +1,188 @@
"use strict";
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
// src/components-page/account-settings/email-and-auth/emails-section.tsx
var emails_section_exports = {};
__export(emails_section_exports, {
EmailsSection: () => EmailsSection
});
module.exports = __toCommonJS(emails_section_exports);
var import_yup = require("@hookform/resolvers/yup");
var import_known_errors = require("@stackframe/stack-shared/dist/known-errors");
var import_schema_fields = require("@stackframe/stack-shared/dist/schema-fields");
var import_promises = require("@stackframe/stack-shared/dist/utils/promises");
var import_stack_ui = require("@stackframe/stack-ui");
var import_react = require("react");
var import_react_hook_form = require("react-hook-form");
var import_form_warning = require("../../../components/elements/form-warning");
var import_hooks = require("../../../lib/hooks");
var import_translations = require("../../../lib/translations");
var import_jsx_runtime = require("react/jsx-runtime");
function EmailsSection() {
const { t } = (0, import_translations.useTranslation)();
const user = (0, import_hooks.useUser)({ or: "redirect" });
const contactChannels = user.useContactChannels();
const [addingEmail, setAddingEmail] = (0, import_react.useState)(contactChannels.length === 0);
const [addingEmailLoading, setAddingEmailLoading] = (0, import_react.useState)(false);
const [addedEmail, setAddedEmail] = (0, import_react.useState)(null);
const isLastEmail = contactChannels.filter((x) => x.usedForAuth && x.type === "email").length === 1;
(0, import_react.useEffect)(() => {
if (addedEmail) {
(0, import_promises.runAsynchronously)(async () => {
const cc = contactChannels.find((x) => x.value === addedEmail);
if (cc && !cc.isVerified) {
await cc.sendVerificationEmail();
}
setAddedEmail(null);
});
}
}, [contactChannels, addedEmail]);
const emailSchema = (0, import_schema_fields.yupObject)({
email: (0, import_schema_fields.strictEmailSchema)(t("Please enter a valid email address")).notOneOf(contactChannels.map((x) => x.value), t("Email already exists")).defined().nonEmpty(t("Email is required"))
});
const { register, handleSubmit, formState: { errors }, reset } = (0, import_react_hook_form.useForm)({
resolver: (0, import_yup.yupResolver)(emailSchema)
});
const onSubmit = async (data) => {
setAddingEmailLoading(true);
try {
await user.createContactChannel({ type: "email", value: data.email, usedForAuth: false });
setAddedEmail(data.email);
} finally {
setAddingEmailLoading(false);
}
setAddingEmail(false);
reset();
};
return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { children: [
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "flex flex-col md:flex-row justify-between mb-4 gap-4", children: [
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_stack_ui.Typography, { className: "font-medium", children: t("Emails") }),
addingEmail ? /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
"form",
{
onSubmit: (e) => {
e.preventDefault();
(0, import_promises.runAsynchronously)(handleSubmit(onSubmit));
},
className: "flex flex-col",
children: [
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "flex gap-2", children: [
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(
import_stack_ui.Input,
{
...register("email"),
placeholder: t("Enter email")
}
),
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_stack_ui.Button, { type: "submit", loading: addingEmailLoading, children: t("Add") }),
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(
import_stack_ui.Button,
{
variant: "secondary",
onClick: () => {
setAddingEmail(false);
reset();
},
children: t("Cancel")
}
)
] }),
errors.email && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_form_warning.FormWarningText, { text: errors.email.message })
]
}
) : /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: "flex md:justify-end", children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_stack_ui.Button, { variant: "secondary", onClick: () => setAddingEmail(true), children: t("Add an email") }) })
] }),
contactChannels.length > 0 ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: "border rounded-md", children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_stack_ui.Table, { children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_stack_ui.TableBody, { children: contactChannels.filter((x) => x.type === "email").sort((a, b) => {
if (a.isPrimary !== b.isPrimary) return a.isPrimary ? -1 : 1;
if (a.isVerified !== b.isVerified) return a.isVerified ? -1 : 1;
return 0;
}).map((x) => /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_stack_ui.TableRow, { children: [
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_stack_ui.TableCell, { children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "flex flex-col md:flex-row gap-2 md:gap-4", children: [
x.value,
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "flex gap-2", children: [
x.isPrimary ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_stack_ui.Badge, { children: t("Primary") }) : null,
!x.isVerified ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_stack_ui.Badge, { variant: "destructive", children: t("Unverified") }) : null,
x.usedForAuth ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_stack_ui.Badge, { variant: "outline", children: t("Used for sign-in") }) : null
] })
] }) }),
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_stack_ui.TableCell, { className: "flex justify-end", children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_stack_ui.ActionCell, { items: [
...!x.isVerified ? [{
item: t("Send verification email"),
onClick: async () => {
await x.sendVerificationEmail();
}
}] : [],
...!x.isPrimary && x.isVerified ? [{
item: t("Set as primary"),
onClick: async () => {
await x.update({ isPrimary: true });
}
}] : !x.isPrimary ? [{
item: t("Set as primary"),
onClick: async () => {
},
disabled: true,
disabledTooltip: t("Please verify your email first")
}] : [],
...!x.usedForAuth && x.isVerified ? [{
item: t("Use for sign-in"),
onClick: async () => {
try {
await x.update({ usedForAuth: true });
} catch (e) {
if (import_known_errors.KnownErrors.ContactChannelAlreadyUsedForAuthBySomeoneElse.isInstance(e)) {
alert(t("This email is already used for sign-in by another user."));
}
}
}
}] : [],
...x.usedForAuth && !isLastEmail ? [{
item: t("Stop using for sign-in"),
onClick: async () => {
await x.update({ usedForAuth: false });
}
}] : x.usedForAuth ? [{
item: t("Stop using for sign-in"),
onClick: async () => {
},
disabled: true,
disabledTooltip: t("You can not remove your last sign-in email")
}] : [],
...!isLastEmail || !x.usedForAuth ? [{
item: t("Remove"),
onClick: async () => {
await x.delete();
},
danger: true
}] : [{
item: t("Remove"),
onClick: async () => {
},
disabled: true,
disabledTooltip: t("You can not remove your last sign-in email")
}]
] }) })
] }, x.id)) }) }) }) : null
] });
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
EmailsSection
});
//# sourceMappingURL=emails-section.js.map

File diff suppressed because one or more lines are too long

View file

@ -0,0 +1,146 @@
"use strict";
var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
// If the importer is in node compatibility mode or this is not an ESM
// file that has been converted to a CommonJS file using a Babel-
// compatible transform (i.e. "__esModule" has not been set), then set
// "default" to the CommonJS "module.exports" for node compatibility.
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
mod
));
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
// src/components-page/account-settings/email-and-auth/mfa-section.tsx
var mfa_section_exports = {};
__export(mfa_section_exports, {
MfaSection: () => MfaSection
});
module.exports = __toCommonJS(mfa_section_exports);
var import_otp = require("@oslojs/otp");
var import_use_async_callback = require("@stackframe/stack-shared/dist/hooks/use-async-callback");
var import_crypto = require("@stackframe/stack-shared/dist/utils/crypto");
var import_errors = require("@stackframe/stack-shared/dist/utils/errors");
var import_promises = require("@stackframe/stack-shared/dist/utils/promises");
var import_stack_ui = require("@stackframe/stack-ui");
var QRCode = __toESM(require("qrcode"));
var import_react = require("react");
var import_hooks = require("../../../lib/hooks");
var import_translations = require("../../../lib/translations");
var import_section = require("../section");
var import_jsx_runtime = require("react/jsx-runtime");
function MfaSection() {
const { t } = (0, import_translations.useTranslation)();
const project = (0, import_hooks.useStackApp)().useProject();
const user = (0, import_hooks.useUser)({ or: "throw" });
const [generatedSecret, setGeneratedSecret] = (0, import_react.useState)(null);
const [qrCodeUrl, setQrCodeUrl] = (0, import_react.useState)(null);
const [mfaCode, setMfaCode] = (0, import_react.useState)("");
const [isMaybeWrong, setIsMaybeWrong] = (0, import_react.useState)(false);
const isEnabled = user.isMultiFactorRequired;
const [handleSubmit, isLoading] = (0, import_use_async_callback.useAsyncCallback)(async () => {
await user.update({
totpMultiFactorSecret: generatedSecret
});
setGeneratedSecret(null);
setQrCodeUrl(null);
setMfaCode("");
}, [generatedSecret, user]);
(0, import_react.useEffect)(() => {
setIsMaybeWrong(false);
(0, import_promises.runAsynchronouslyWithAlert)(async () => {
if (generatedSecret && (0, import_otp.verifyTOTP)(generatedSecret, 30, 6, mfaCode)) {
await handleSubmit();
}
setIsMaybeWrong(true);
});
}, [mfaCode, generatedSecret, handleSubmit]);
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
import_section.Section,
{
title: t("Multi-factor authentication"),
description: isEnabled ? t("Multi-factor authentication is currently enabled.") : t("Multi-factor authentication is currently disabled."),
children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "flex flex-col gap-4", children: [
!isEnabled && generatedSecret && /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, { children: [
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_stack_ui.Typography, { children: t("Scan this QR code with your authenticator app:") }),
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("img", { width: 200, height: 200, src: qrCodeUrl ?? (0, import_errors.throwErr)("TOTP QR code failed to generate"), alt: t("TOTP multi-factor authentication QR code") }),
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_stack_ui.Typography, { children: t("Then, enter your six-digit MFA code:") }),
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(
import_stack_ui.Input,
{
value: mfaCode,
onChange: (e) => {
setIsMaybeWrong(false);
setMfaCode(e.target.value);
},
placeholder: "123456",
maxLength: 6,
disabled: isLoading
}
),
isMaybeWrong && mfaCode.length === 6 && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_stack_ui.Typography, { variant: "destructive", children: t("Incorrect code. Please try again.") }),
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: "flex", children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
import_stack_ui.Button,
{
variant: "secondary",
onClick: () => {
setGeneratedSecret(null);
setQrCodeUrl(null);
setMfaCode("");
},
children: t("Cancel")
}
) })
] }),
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: "flex gap-2", children: isEnabled ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
import_stack_ui.Button,
{
variant: "secondary",
onClick: async () => {
await user.update({
totpMultiFactorSecret: null
});
},
children: t("Disable MFA")
}
) : !generatedSecret && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
import_stack_ui.Button,
{
variant: "secondary",
onClick: async () => {
const secret = (0, import_crypto.generateRandomValues)(new Uint8Array(20));
setQrCodeUrl(await generateTotpQrCode(project, user, secret));
setGeneratedSecret(secret);
},
children: t("Enable MFA")
}
) })
] })
}
);
}
async function generateTotpQrCode(project, user, secret) {
const uri = (0, import_otp.createTOTPKeyURI)(project.displayName, user.primaryEmail ?? user.id, secret, 30, 6);
return await QRCode.toDataURL(uri);
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
MfaSection
});
//# sourceMappingURL=mfa-section.js.map

File diff suppressed because one or more lines are too long

View file

@ -0,0 +1,89 @@
"use strict";
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
// src/components-page/account-settings/email-and-auth/otp-section.tsx
var otp_section_exports = {};
__export(otp_section_exports, {
OtpSection: () => OtpSection
});
module.exports = __toCommonJS(otp_section_exports);
var import_stack_ui = require("@stackframe/stack-ui");
var import_react = require("react");
var import_hooks = require("../../../lib/hooks");
var import_translations = require("../../../lib/translations");
var import_section = require("../section");
var import_jsx_runtime = require("react/jsx-runtime");
function OtpSection() {
const { t } = (0, import_translations.useTranslation)();
const user = (0, import_hooks.useUser)({ or: "throw" });
const project = (0, import_hooks.useStackApp)().useProject();
const contactChannels = user.useContactChannels();
const isLastAuth = user.otpAuthEnabled && !user.hasPassword && user.oauthProviders.length === 0 && !user.passkeyAuthEnabled;
const [disabling, setDisabling] = (0, import_react.useState)(false);
const hasValidEmail = contactChannels.filter((x) => x.type === "email" && x.isVerified && x.usedForAuth).length > 0;
if (!project.config.magicLinkEnabled) {
return null;
}
const handleDisableOTP = async () => {
await user.update({ otpAuthEnabled: false });
setDisabling(false);
};
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_section.Section, { title: t("OTP sign-in"), description: user.otpAuthEnabled ? t("OTP/magic link sign-in is currently enabled.") : t("Enable sign-in via magic link or OTP sent to your sign-in emails."), children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: "flex md:justify-end", children: hasValidEmail ? user.otpAuthEnabled ? !isLastAuth ? !disabling ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
import_stack_ui.Button,
{
variant: "secondary",
onClick: () => setDisabling(true),
children: t("Disable OTP")
}
) : /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "flex flex-col gap-2", children: [
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_stack_ui.Typography, { variant: "destructive", children: t("Are you sure you want to disable OTP sign-in? You will not be able to sign in with only emails anymore.") }),
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "flex gap-2", children: [
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(
import_stack_ui.Button,
{
variant: "destructive",
onClick: handleDisableOTP,
children: t("Disable")
}
),
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(
import_stack_ui.Button,
{
variant: "secondary",
onClick: () => setDisabling(false),
children: t("Cancel")
}
)
] })
] }) : /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_stack_ui.Typography, { variant: "secondary", type: "label", children: t("OTP sign-in is enabled and cannot be disabled as it is currently the only sign-in method") }) : /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
import_stack_ui.Button,
{
variant: "secondary",
onClick: async () => {
await user.update({ otpAuthEnabled: true });
},
children: t("Enable OTP")
}
) : /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_stack_ui.Typography, { variant: "secondary", type: "label", children: t("To enable OTP sign-in, please add a verified sign-in email.") }) }) });
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
OtpSection
});
//# sourceMappingURL=otp-section.js.map

View file

@ -0,0 +1 @@
{"version":3,"sources":["../../../../src/components-page/account-settings/email-and-auth/otp-section.tsx"],"sourcesContent":["\n//===========================================\n// THIS FILE IS AUTO-GENERATED FROM TEMPLATE. DO NOT EDIT IT DIRECTLY\n//===========================================\nimport { Button, Typography } from \"@stackframe/stack-ui\";\nimport { useState } from \"react\";\nimport { useStackApp, useUser } from \"../../../lib/hooks\";\nimport { useTranslation } from \"../../../lib/translations\";\nimport { Section } from \"../section\";\n\nexport function OtpSection() {\n const { t } = useTranslation();\n const user = useUser({ or: \"throw\" });\n const project = useStackApp().useProject();\n const contactChannels = user.useContactChannels();\n const isLastAuth = user.otpAuthEnabled && !user.hasPassword && user.oauthProviders.length === 0 && !user.passkeyAuthEnabled;\n const [disabling, setDisabling] = useState(false);\n\n // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition\n const hasValidEmail = contactChannels.filter(x => x.type === 'email' && x.isVerified && x.usedForAuth).length > 0;\n\n if (!project.config.magicLinkEnabled) {\n return null;\n }\n\n const handleDisableOTP = async () => {\n await user.update({ otpAuthEnabled: false });\n setDisabling(false);\n };\n\n return (\n <Section title={t(\"OTP sign-in\")} description={user.otpAuthEnabled ? t(\"OTP/magic link sign-in is currently enabled.\") : t(\"Enable sign-in via magic link or OTP sent to your sign-in emails.\")}>\n <div className='flex md:justify-end'>\n {hasValidEmail ? (\n user.otpAuthEnabled ? (\n !isLastAuth ? (\n !disabling ? (\n <Button\n variant='secondary'\n onClick={() => setDisabling(true)}\n >\n {t(\"Disable OTP\")}\n </Button>\n ) : (\n <div className='flex flex-col gap-2'>\n <Typography variant='destructive'>\n {t(\"Are you sure you want to disable OTP sign-in? You will not be able to sign in with only emails anymore.\")}\n </Typography>\n <div className='flex gap-2'>\n <Button\n variant='destructive'\n onClick={handleDisableOTP}\n >\n {t(\"Disable\")}\n </Button>\n <Button\n variant='secondary'\n onClick={() => setDisabling(false)}\n >\n {t(\"Cancel\")}\n </Button>\n </div>\n </div>\n )\n ) : (\n <Typography variant='secondary' type='label'>{t(\"OTP sign-in is enabled and cannot be disabled as it is currently the only sign-in method\")}</Typography>\n )\n ) : (\n <Button\n variant='secondary'\n onClick={async () => {\n await user.update({ otpAuthEnabled: true });\n }}\n >\n {t(\"Enable OTP\")}\n </Button>\n )\n ) : (\n <Typography variant='secondary' type='label'>{t(\"To enable OTP sign-in, please add a verified sign-in email.\")}</Typography>\n )}\n </div>\n </Section>\n );\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAIA,sBAAmC;AACnC,mBAAyB;AACzB,mBAAqC;AACrC,0BAA+B;AAC/B,qBAAwB;AA6BR;AA3BT,SAAS,aAAa;AAC3B,QAAM,EAAE,EAAE,QAAI,oCAAe;AAC7B,QAAM,WAAO,sBAAQ,EAAE,IAAI,QAAQ,CAAC;AACpC,QAAM,cAAU,0BAAY,EAAE,WAAW;AACzC,QAAM,kBAAkB,KAAK,mBAAmB;AAChD,QAAM,aAAa,KAAK,kBAAkB,CAAC,KAAK,eAAe,KAAK,eAAe,WAAW,KAAK,CAAC,KAAK;AACzG,QAAM,CAAC,WAAW,YAAY,QAAI,uBAAS,KAAK;AAGhD,QAAM,gBAAgB,gBAAgB,OAAO,OAAK,EAAE,SAAS,WAAW,EAAE,cAAc,EAAE,WAAW,EAAE,SAAS;AAEhH,MAAI,CAAC,QAAQ,OAAO,kBAAkB;AACpC,WAAO;AAAA,EACT;AAEA,QAAM,mBAAmB,YAAY;AACnC,UAAM,KAAK,OAAO,EAAE,gBAAgB,MAAM,CAAC;AAC3C,iBAAa,KAAK;AAAA,EACpB;AAEA,SACE,4CAAC,0BAAQ,OAAO,EAAE,aAAa,GAAG,aAAa,KAAK,iBAAiB,EAAE,8CAA8C,IAAI,EAAE,mEAAmE,GAC5L,sDAAC,SAAI,WAAU,uBACZ,0BACC,KAAK,iBACH,CAAC,aACC,CAAC,YACC;AAAA,IAAC;AAAA;AAAA,MACC,SAAQ;AAAA,MACR,SAAS,MAAM,aAAa,IAAI;AAAA,MAE/B,YAAE,aAAa;AAAA;AAAA,EAClB,IAEA,6CAAC,SAAI,WAAU,uBACb;AAAA,gDAAC,8BAAW,SAAQ,eACjB,YAAE,yGAAyG,GAC9G;AAAA,IACA,6CAAC,SAAI,WAAU,cACb;AAAA;AAAA,QAAC;AAAA;AAAA,UACC,SAAQ;AAAA,UACR,SAAS;AAAA,UAER,YAAE,SAAS;AAAA;AAAA,MACd;AAAA,MACA;AAAA,QAAC;AAAA;AAAA,UACC,SAAQ;AAAA,UACR,SAAS,MAAM,aAAa,KAAK;AAAA,UAEhC,YAAE,QAAQ;AAAA;AAAA,MACb;AAAA,OACF;AAAA,KACF,IAGF,4CAAC,8BAAW,SAAQ,aAAY,MAAK,SAAS,YAAE,0FAA0F,GAAE,IAG9I;AAAA,IAAC;AAAA;AAAA,MACC,SAAQ;AAAA,MACR,SAAS,YAAY;AACnB,cAAM,KAAK,OAAO,EAAE,gBAAgB,KAAK,CAAC;AAAA,MAC5C;AAAA,MAEC,YAAE,YAAY;AAAA;AAAA,EACjB,IAGF,4CAAC,8BAAW,SAAQ,aAAY,MAAK,SAAS,YAAE,6DAA6D,GAAE,GAEnH,GACF;AAEJ;","names":[]}

View file

@ -0,0 +1,92 @@
"use strict";
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
// src/components-page/account-settings/email-and-auth/passkey-section.tsx
var passkey_section_exports = {};
__export(passkey_section_exports, {
PasskeySection: () => PasskeySection
});
module.exports = __toCommonJS(passkey_section_exports);
var import_stack_ui = require("@stackframe/stack-ui");
var import_react = require("react");
var import__ = require("../../..");
var import_hooks = require("../../../lib/hooks");
var import_translations = require("../../../lib/translations");
var import_section = require("../section");
var import_jsx_runtime = require("react/jsx-runtime");
function PasskeySection() {
const { t } = (0, import_translations.useTranslation)();
const user = (0, import_hooks.useUser)({ or: "throw" });
const stackApp = (0, import__.useStackApp)();
const project = stackApp.useProject();
const contactChannels = user.useContactChannels();
const hasPasskey = user.passkeyAuthEnabled;
const isLastAuth = user.passkeyAuthEnabled && !user.hasPassword && user.oauthProviders.length === 0 && !user.otpAuthEnabled;
const [showConfirmationModal, setShowConfirmationModal] = (0, import_react.useState)(false);
const hasValidEmail = contactChannels.filter((x) => x.type === "email" && x.isVerified && x.usedForAuth).length > 0;
if (!project.config.passkeyEnabled) {
return null;
}
const handleDeletePasskey = async () => {
await user.update({ passkeyAuthEnabled: false });
setShowConfirmationModal(false);
};
const handleAddNewPasskey = async () => {
await user.registerPasskey();
};
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_jsx_runtime.Fragment, { children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_section.Section, { title: t("Passkey"), description: hasPasskey ? t("Passkey registered") : t("Register a passkey"), children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "flex md:justify-end gap-2", children: [
!hasValidEmail && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_stack_ui.Typography, { variant: "secondary", type: "label", children: t("To enable Passkey sign-in, please add a verified sign-in email.") }),
hasValidEmail && hasPasskey && isLastAuth && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_stack_ui.Typography, { variant: "secondary", type: "label", children: t("Passkey sign-in is enabled and cannot be disabled as it is currently the only sign-in method") }),
!hasPasskey && hasValidEmail && /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_stack_ui.Button, { onClick: handleAddNewPasskey, variant: "secondary", children: t("Add new passkey") }) }),
hasValidEmail && hasPasskey && !isLastAuth && !showConfirmationModal && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
import_stack_ui.Button,
{
variant: "secondary",
onClick: () => setShowConfirmationModal(true),
children: t("Delete Passkey")
}
),
hasValidEmail && hasPasskey && !isLastAuth && showConfirmationModal && /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "flex flex-col gap-2", children: [
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_stack_ui.Typography, { variant: "destructive", children: t("Are you sure you want to disable Passkey sign-in? You will not be able to sign in with your passkey anymore.") }),
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "flex gap-2", children: [
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(
import_stack_ui.Button,
{
variant: "destructive",
onClick: handleDeletePasskey,
children: t("Disable")
}
),
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(
import_stack_ui.Button,
{
variant: "secondary",
onClick: () => setShowConfirmationModal(false),
children: t("Cancel")
}
)
] })
] })
] }) }) });
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
PasskeySection
});
//# sourceMappingURL=passkey-section.js.map

File diff suppressed because one or more lines are too long

View file

@ -0,0 +1,181 @@
"use strict";
var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
// If the importer is in node compatibility mode or this is not an ESM
// file that has been converted to a CommonJS file using a Babel-
// compatible transform (i.e. "__esModule" has not been set), then set
// "default" to the CommonJS "module.exports" for node compatibility.
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
mod
));
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
// src/components-page/account-settings/email-and-auth/password-section.tsx
var password_section_exports = {};
__export(password_section_exports, {
PasswordSection: () => PasswordSection
});
module.exports = __toCommonJS(password_section_exports);
var import_yup = require("@hookform/resolvers/yup");
var import_password = require("@stackframe/stack-shared/dist/helpers/password");
var import_schema_fields = require("@stackframe/stack-shared/dist/schema-fields");
var import_promises = require("@stackframe/stack-shared/dist/utils/promises");
var import_stack_ui = require("@stackframe/stack-ui");
var import_react = require("react");
var import_react_hook_form = require("react-hook-form");
var yup = __toESM(require("yup"));
var import__ = require("../../..");
var import_form_warning = require("../../../components/elements/form-warning");
var import_hooks = require("../../../lib/hooks");
var import_translations = require("../../../lib/translations");
var import_section = require("../section");
var import_jsx_runtime = require("react/jsx-runtime");
function PasswordSection() {
const { t } = (0, import_translations.useTranslation)();
const user = (0, import_hooks.useUser)({ or: "throw" });
const contactChannels = user.useContactChannels();
const [changingPassword, setChangingPassword] = (0, import_react.useState)(false);
const [loading, setLoading] = (0, import_react.useState)(false);
const project = (0, import__.useStackApp)().useProject();
const passwordSchema = (0, import_schema_fields.yupObject)({
oldPassword: user.hasPassword ? import_schema_fields.passwordSchema.defined().nonEmpty(t("Please enter your old password")) : (0, import_schema_fields.yupString)(),
newPassword: import_schema_fields.passwordSchema.defined().nonEmpty(t("Please enter your password")).test({
name: "is-valid-password",
test: (value, ctx) => {
const error = (0, import_password.getPasswordError)(value);
if (error) {
return ctx.createError({ message: error.message });
} else {
return true;
}
}
}),
newPasswordRepeat: (0, import_schema_fields.yupString)().nullable().oneOf([yup.ref("newPassword"), "", null], t("Passwords do not match")).defined().nonEmpty(t("Please repeat your password"))
});
const { register, handleSubmit, setError, formState: { errors }, clearErrors, reset } = (0, import_react_hook_form.useForm)({
resolver: (0, import_yup.yupResolver)(passwordSchema)
});
const hasValidEmail = contactChannels.filter((x) => x.type === "email" && x.usedForAuth).length > 0;
const onSubmit = async (data) => {
setLoading(true);
try {
const { oldPassword, newPassword } = data;
const error = user.hasPassword ? await user.updatePassword({ oldPassword, newPassword }) : await user.setPassword({ password: newPassword });
if (error) {
setError("oldPassword", { type: "manual", message: t("Incorrect password") });
} else {
reset();
setChangingPassword(false);
}
} finally {
setLoading(false);
}
};
const registerPassword = register("newPassword");
const registerPasswordRepeat = register("newPasswordRepeat");
if (!project.config.credentialEnabled) {
return null;
}
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
import_section.Section,
{
title: t("Password"),
description: user.hasPassword ? t("Update your password") : t("Set a password for your account"),
children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: "flex flex-col gap-4", children: !changingPassword ? hasValidEmail ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
import_stack_ui.Button,
{
variant: "secondary",
onClick: () => setChangingPassword(true),
children: user.hasPassword ? t("Update password") : t("Set password")
}
) : /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_stack_ui.Typography, { variant: "secondary", type: "label", children: t("To set a password, please add a sign-in email.") }) : /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
"form",
{
onSubmit: (e) => (0, import_promises.runAsynchronouslyWithAlert)(handleSubmit(onSubmit)(e)),
noValidate: true,
children: [
user.hasPassword && /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, { children: [
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_stack_ui.Label, { htmlFor: "old-password", className: "mb-1", children: t("Old password") }),
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(
import_stack_ui.Input,
{
id: "old-password",
type: "password",
autoComplete: "current-password",
...register("oldPassword")
}
),
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_form_warning.FormWarningText, { text: errors.oldPassword?.message?.toString() })
] }),
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_stack_ui.Label, { htmlFor: "new-password", className: "mt-4 mb-1", children: t("New password") }),
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(
import_stack_ui.PasswordInput,
{
id: "new-password",
autoComplete: "new-password",
...registerPassword,
onChange: (e) => {
clearErrors("newPassword");
clearErrors("newPasswordRepeat");
(0, import_promises.runAsynchronously)(registerPassword.onChange(e));
}
}
),
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_form_warning.FormWarningText, { text: errors.newPassword?.message?.toString() }),
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_stack_ui.Label, { htmlFor: "repeat-password", className: "mt-4 mb-1", children: t("Repeat new password") }),
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(
import_stack_ui.PasswordInput,
{
id: "repeat-password",
autoComplete: "new-password",
...registerPasswordRepeat,
onChange: (e) => {
clearErrors("newPassword");
clearErrors("newPasswordRepeat");
(0, import_promises.runAsynchronously)(registerPasswordRepeat.onChange(e));
}
}
),
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_form_warning.FormWarningText, { text: errors.newPasswordRepeat?.message?.toString() }),
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "mt-6 flex gap-4", children: [
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_stack_ui.Button, { type: "submit", loading, children: user.hasPassword ? t("Update Password") : t("Set Password") }),
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(
import_stack_ui.Button,
{
variant: "secondary",
onClick: () => {
setChangingPassword(false);
reset();
},
children: t("Cancel")
}
)
] })
]
}
) })
}
);
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
PasswordSection
});
//# sourceMappingURL=password-section.js.map

File diff suppressed because one or more lines are too long