mirror of
https://github.com/eigent-ai/eigent.git
synced 2026-04-29 04:00:09 +00:00
Initial commit of eigent-main
This commit is contained in:
commit
723df5a03e
1144 changed files with 103478 additions and 0 deletions
|
|
@ -0,0 +1,21 @@
|
|||
// src/components-page/account-settings/email-and-auth/email-and-auth-page.tsx
|
||||
import { PageLayout } from "../page-layout";
|
||||
import { EmailsSection } from "./emails-section";
|
||||
import { MfaSection } from "./mfa-section";
|
||||
import { OtpSection } from "./otp-section";
|
||||
import { PasskeySection } from "./passkey-section";
|
||||
import { PasswordSection } from "./password-section";
|
||||
import { jsx, jsxs } from "react/jsx-runtime";
|
||||
function EmailsAndAuthPage() {
|
||||
return /* @__PURE__ */ jsxs(PageLayout, { children: [
|
||||
/* @__PURE__ */ jsx(EmailsSection, {}),
|
||||
/* @__PURE__ */ jsx(PasswordSection, {}),
|
||||
/* @__PURE__ */ jsx(PasskeySection, {}),
|
||||
/* @__PURE__ */ jsx(OtpSection, {}),
|
||||
/* @__PURE__ */ jsx(MfaSection, {})
|
||||
] });
|
||||
}
|
||||
export {
|
||||
EmailsAndAuthPage
|
||||
};
|
||||
//# sourceMappingURL=email-and-auth-page.js.map
|
||||
|
|
@ -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":";AAIA,SAAS,kBAAkB;AAC3B,SAAS,qBAAqB;AAC9B,SAAS,kBAAkB;AAC3B,SAAS,kBAAkB;AAC3B,SAAS,sBAAsB;AAC/B,SAAS,uBAAuB;AAI5B,SACE,KADF;AAFG,SAAS,oBAAoB;AAClC,SACE,qBAAC,cACC;AAAA,wBAAC,iBAAa;AAAA,IACd,oBAAC,mBAAgB;AAAA,IACjB,oBAAC,kBAAe;AAAA,IAChB,oBAAC,cAAW;AAAA,IACZ,oBAAC,cAAW;AAAA,KACd;AAEJ;","names":[]}
|
||||
163
package/@stackframe/react/dist/esm/components-page/account-settings/email-and-auth/emails-section.js
vendored
Normal file
163
package/@stackframe/react/dist/esm/components-page/account-settings/email-and-auth/emails-section.js
vendored
Normal file
|
|
@ -0,0 +1,163 @@
|
|||
// src/components-page/account-settings/email-and-auth/emails-section.tsx
|
||||
import { yupResolver } from "@hookform/resolvers/yup";
|
||||
import { KnownErrors } from "@stackframe/stack-shared/dist/known-errors";
|
||||
import { strictEmailSchema, yupObject } from "@stackframe/stack-shared/dist/schema-fields";
|
||||
import { runAsynchronously } from "@stackframe/stack-shared/dist/utils/promises";
|
||||
import { ActionCell, Badge, Button, Input, Table, TableBody, TableCell, TableRow, Typography } from "@stackframe/stack-ui";
|
||||
import { useEffect, useState } from "react";
|
||||
import { useForm } from "react-hook-form";
|
||||
import { FormWarningText } from "../../../components/elements/form-warning";
|
||||
import { useUser } from "../../../lib/hooks";
|
||||
import { useTranslation } from "../../../lib/translations";
|
||||
import { jsx, jsxs } from "react/jsx-runtime";
|
||||
function EmailsSection() {
|
||||
const { t } = useTranslation();
|
||||
const user = useUser({ or: "redirect" });
|
||||
const contactChannels = user.useContactChannels();
|
||||
const [addingEmail, setAddingEmail] = useState(contactChannels.length === 0);
|
||||
const [addingEmailLoading, setAddingEmailLoading] = useState(false);
|
||||
const [addedEmail, setAddedEmail] = useState(null);
|
||||
const isLastEmail = contactChannels.filter((x) => x.usedForAuth && x.type === "email").length === 1;
|
||||
useEffect(() => {
|
||||
if (addedEmail) {
|
||||
runAsynchronously(async () => {
|
||||
const cc = contactChannels.find((x) => x.value === addedEmail);
|
||||
if (cc && !cc.isVerified) {
|
||||
await cc.sendVerificationEmail();
|
||||
}
|
||||
setAddedEmail(null);
|
||||
});
|
||||
}
|
||||
}, [contactChannels, addedEmail]);
|
||||
const emailSchema = yupObject({
|
||||
email: 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 } = useForm({
|
||||
resolver: 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__ */ jsxs("div", { children: [
|
||||
/* @__PURE__ */ jsxs("div", { className: "flex flex-col md:flex-row justify-between mb-4 gap-4", children: [
|
||||
/* @__PURE__ */ jsx(Typography, { className: "font-medium", children: t("Emails") }),
|
||||
addingEmail ? /* @__PURE__ */ jsxs(
|
||||
"form",
|
||||
{
|
||||
onSubmit: (e) => {
|
||||
e.preventDefault();
|
||||
runAsynchronously(handleSubmit(onSubmit));
|
||||
},
|
||||
className: "flex flex-col",
|
||||
children: [
|
||||
/* @__PURE__ */ jsxs("div", { className: "flex gap-2", children: [
|
||||
/* @__PURE__ */ jsx(
|
||||
Input,
|
||||
{
|
||||
...register("email"),
|
||||
placeholder: t("Enter email")
|
||||
}
|
||||
),
|
||||
/* @__PURE__ */ jsx(Button, { type: "submit", loading: addingEmailLoading, children: t("Add") }),
|
||||
/* @__PURE__ */ jsx(
|
||||
Button,
|
||||
{
|
||||
variant: "secondary",
|
||||
onClick: () => {
|
||||
setAddingEmail(false);
|
||||
reset();
|
||||
},
|
||||
children: t("Cancel")
|
||||
}
|
||||
)
|
||||
] }),
|
||||
errors.email && /* @__PURE__ */ jsx(FormWarningText, { text: errors.email.message })
|
||||
]
|
||||
}
|
||||
) : /* @__PURE__ */ jsx("div", { className: "flex md:justify-end", children: /* @__PURE__ */ jsx(Button, { variant: "secondary", onClick: () => setAddingEmail(true), children: t("Add an email") }) })
|
||||
] }),
|
||||
contactChannels.length > 0 ? /* @__PURE__ */ jsx("div", { className: "border rounded-md", children: /* @__PURE__ */ jsx(Table, { children: /* @__PURE__ */ jsx(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__ */ jsxs(TableRow, { children: [
|
||||
/* @__PURE__ */ jsx(TableCell, { children: /* @__PURE__ */ jsxs("div", { className: "flex flex-col md:flex-row gap-2 md:gap-4", children: [
|
||||
x.value,
|
||||
/* @__PURE__ */ jsxs("div", { className: "flex gap-2", children: [
|
||||
x.isPrimary ? /* @__PURE__ */ jsx(Badge, { children: t("Primary") }) : null,
|
||||
!x.isVerified ? /* @__PURE__ */ jsx(Badge, { variant: "destructive", children: t("Unverified") }) : null,
|
||||
x.usedForAuth ? /* @__PURE__ */ jsx(Badge, { variant: "outline", children: t("Used for sign-in") }) : null
|
||||
] })
|
||||
] }) }),
|
||||
/* @__PURE__ */ jsx(TableCell, { className: "flex justify-end", children: /* @__PURE__ */ jsx(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 (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
|
||||
] });
|
||||
}
|
||||
export {
|
||||
EmailsSection
|
||||
};
|
||||
//# sourceMappingURL=emails-section.js.map
|
||||
File diff suppressed because one or more lines are too long
111
package/@stackframe/react/dist/esm/components-page/account-settings/email-and-auth/mfa-section.js
vendored
Normal file
111
package/@stackframe/react/dist/esm/components-page/account-settings/email-and-auth/mfa-section.js
vendored
Normal file
|
|
@ -0,0 +1,111 @@
|
|||
// src/components-page/account-settings/email-and-auth/mfa-section.tsx
|
||||
import { createTOTPKeyURI, verifyTOTP } from "@oslojs/otp";
|
||||
import { useAsyncCallback } from "@stackframe/stack-shared/dist/hooks/use-async-callback";
|
||||
import { generateRandomValues } from "@stackframe/stack-shared/dist/utils/crypto";
|
||||
import { throwErr } from "@stackframe/stack-shared/dist/utils/errors";
|
||||
import { runAsynchronouslyWithAlert } from "@stackframe/stack-shared/dist/utils/promises";
|
||||
import { Button, Input, Typography } from "@stackframe/stack-ui";
|
||||
import * as QRCode from "qrcode";
|
||||
import { useEffect, useState } from "react";
|
||||
import { useStackApp, useUser } from "../../../lib/hooks";
|
||||
import { useTranslation } from "../../../lib/translations";
|
||||
import { Section } from "../section";
|
||||
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
||||
function MfaSection() {
|
||||
const { t } = useTranslation();
|
||||
const project = useStackApp().useProject();
|
||||
const user = useUser({ or: "throw" });
|
||||
const [generatedSecret, setGeneratedSecret] = useState(null);
|
||||
const [qrCodeUrl, setQrCodeUrl] = useState(null);
|
||||
const [mfaCode, setMfaCode] = useState("");
|
||||
const [isMaybeWrong, setIsMaybeWrong] = useState(false);
|
||||
const isEnabled = user.isMultiFactorRequired;
|
||||
const [handleSubmit, isLoading] = useAsyncCallback(async () => {
|
||||
await user.update({
|
||||
totpMultiFactorSecret: generatedSecret
|
||||
});
|
||||
setGeneratedSecret(null);
|
||||
setQrCodeUrl(null);
|
||||
setMfaCode("");
|
||||
}, [generatedSecret, user]);
|
||||
useEffect(() => {
|
||||
setIsMaybeWrong(false);
|
||||
runAsynchronouslyWithAlert(async () => {
|
||||
if (generatedSecret && verifyTOTP(generatedSecret, 30, 6, mfaCode)) {
|
||||
await handleSubmit();
|
||||
}
|
||||
setIsMaybeWrong(true);
|
||||
});
|
||||
}, [mfaCode, generatedSecret, handleSubmit]);
|
||||
return /* @__PURE__ */ jsx(
|
||||
Section,
|
||||
{
|
||||
title: t("Multi-factor authentication"),
|
||||
description: isEnabled ? t("Multi-factor authentication is currently enabled.") : t("Multi-factor authentication is currently disabled."),
|
||||
children: /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-4", children: [
|
||||
!isEnabled && generatedSecret && /* @__PURE__ */ jsxs(Fragment, { children: [
|
||||
/* @__PURE__ */ jsx(Typography, { children: t("Scan this QR code with your authenticator app:") }),
|
||||
/* @__PURE__ */ jsx("img", { width: 200, height: 200, src: qrCodeUrl ?? throwErr("TOTP QR code failed to generate"), alt: t("TOTP multi-factor authentication QR code") }),
|
||||
/* @__PURE__ */ jsx(Typography, { children: t("Then, enter your six-digit MFA code:") }),
|
||||
/* @__PURE__ */ jsx(
|
||||
Input,
|
||||
{
|
||||
value: mfaCode,
|
||||
onChange: (e) => {
|
||||
setIsMaybeWrong(false);
|
||||
setMfaCode(e.target.value);
|
||||
},
|
||||
placeholder: "123456",
|
||||
maxLength: 6,
|
||||
disabled: isLoading
|
||||
}
|
||||
),
|
||||
isMaybeWrong && mfaCode.length === 6 && /* @__PURE__ */ jsx(Typography, { variant: "destructive", children: t("Incorrect code. Please try again.") }),
|
||||
/* @__PURE__ */ jsx("div", { className: "flex", children: /* @__PURE__ */ jsx(
|
||||
Button,
|
||||
{
|
||||
variant: "secondary",
|
||||
onClick: () => {
|
||||
setGeneratedSecret(null);
|
||||
setQrCodeUrl(null);
|
||||
setMfaCode("");
|
||||
},
|
||||
children: t("Cancel")
|
||||
}
|
||||
) })
|
||||
] }),
|
||||
/* @__PURE__ */ jsx("div", { className: "flex gap-2", children: isEnabled ? /* @__PURE__ */ jsx(
|
||||
Button,
|
||||
{
|
||||
variant: "secondary",
|
||||
onClick: async () => {
|
||||
await user.update({
|
||||
totpMultiFactorSecret: null
|
||||
});
|
||||
},
|
||||
children: t("Disable MFA")
|
||||
}
|
||||
) : !generatedSecret && /* @__PURE__ */ jsx(
|
||||
Button,
|
||||
{
|
||||
variant: "secondary",
|
||||
onClick: async () => {
|
||||
const secret = generateRandomValues(new Uint8Array(20));
|
||||
setQrCodeUrl(await generateTotpQrCode(project, user, secret));
|
||||
setGeneratedSecret(secret);
|
||||
},
|
||||
children: t("Enable MFA")
|
||||
}
|
||||
) })
|
||||
] })
|
||||
}
|
||||
);
|
||||
}
|
||||
async function generateTotpQrCode(project, user, secret) {
|
||||
const uri = createTOTPKeyURI(project.displayName, user.primaryEmail ?? user.id, secret, 30, 6);
|
||||
return await QRCode.toDataURL(uri);
|
||||
}
|
||||
export {
|
||||
MfaSection
|
||||
};
|
||||
//# sourceMappingURL=mfa-section.js.map
|
||||
File diff suppressed because one or more lines are too long
|
|
@ -0,0 +1,64 @@
|
|||
// src/components-page/account-settings/email-and-auth/otp-section.tsx
|
||||
import { Button, Typography } from "@stackframe/stack-ui";
|
||||
import { useState } from "react";
|
||||
import { useStackApp, useUser } from "../../../lib/hooks";
|
||||
import { useTranslation } from "../../../lib/translations";
|
||||
import { Section } from "../section";
|
||||
import { jsx, jsxs } from "react/jsx-runtime";
|
||||
function OtpSection() {
|
||||
const { t } = useTranslation();
|
||||
const user = useUser({ or: "throw" });
|
||||
const project = useStackApp().useProject();
|
||||
const contactChannels = user.useContactChannels();
|
||||
const isLastAuth = user.otpAuthEnabled && !user.hasPassword && user.oauthProviders.length === 0 && !user.passkeyAuthEnabled;
|
||||
const [disabling, setDisabling] = 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__ */ jsx(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__ */ jsx("div", { className: "flex md:justify-end", children: hasValidEmail ? user.otpAuthEnabled ? !isLastAuth ? !disabling ? /* @__PURE__ */ jsx(
|
||||
Button,
|
||||
{
|
||||
variant: "secondary",
|
||||
onClick: () => setDisabling(true),
|
||||
children: t("Disable OTP")
|
||||
}
|
||||
) : /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-2", children: [
|
||||
/* @__PURE__ */ jsx(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__ */ jsxs("div", { className: "flex gap-2", children: [
|
||||
/* @__PURE__ */ jsx(
|
||||
Button,
|
||||
{
|
||||
variant: "destructive",
|
||||
onClick: handleDisableOTP,
|
||||
children: t("Disable")
|
||||
}
|
||||
),
|
||||
/* @__PURE__ */ jsx(
|
||||
Button,
|
||||
{
|
||||
variant: "secondary",
|
||||
onClick: () => setDisabling(false),
|
||||
children: t("Cancel")
|
||||
}
|
||||
)
|
||||
] })
|
||||
] }) : /* @__PURE__ */ jsx(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__ */ jsx(
|
||||
Button,
|
||||
{
|
||||
variant: "secondary",
|
||||
onClick: async () => {
|
||||
await user.update({ otpAuthEnabled: true });
|
||||
},
|
||||
children: t("Enable OTP")
|
||||
}
|
||||
) : /* @__PURE__ */ jsx(Typography, { variant: "secondary", type: "label", children: t("To enable OTP sign-in, please add a verified sign-in email.") }) }) });
|
||||
}
|
||||
export {
|
||||
OtpSection
|
||||
};
|
||||
//# sourceMappingURL=otp-section.js.map
|
||||
|
|
@ -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":";AAIA,SAAS,QAAQ,kBAAkB;AACnC,SAAS,gBAAgB;AACzB,SAAS,aAAa,eAAe;AACrC,SAAS,sBAAsB;AAC/B,SAAS,eAAe;AA6BR,cAWE,YAXF;AA3BT,SAAS,aAAa;AAC3B,QAAM,EAAE,EAAE,IAAI,eAAe;AAC7B,QAAM,OAAO,QAAQ,EAAE,IAAI,QAAQ,CAAC;AACpC,QAAM,UAAU,YAAY,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,IAAI,SAAS,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,oBAAC,WAAQ,OAAO,EAAE,aAAa,GAAG,aAAa,KAAK,iBAAiB,EAAE,8CAA8C,IAAI,EAAE,mEAAmE,GAC5L,8BAAC,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,qBAAC,SAAI,WAAU,uBACb;AAAA,wBAAC,cAAW,SAAQ,eACjB,YAAE,yGAAyG,GAC9G;AAAA,IACA,qBAAC,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,oBAAC,cAAW,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,oBAAC,cAAW,SAAQ,aAAY,MAAK,SAAS,YAAE,6DAA6D,GAAE,GAEnH,GACF;AAEJ;","names":[]}
|
||||
|
|
@ -0,0 +1,67 @@
|
|||
// src/components-page/account-settings/email-and-auth/passkey-section.tsx
|
||||
import { Button, Typography } from "@stackframe/stack-ui";
|
||||
import { useState } from "react";
|
||||
import { useStackApp } from "../../..";
|
||||
import { useUser } from "../../../lib/hooks";
|
||||
import { useTranslation } from "../../../lib/translations";
|
||||
import { Section } from "../section";
|
||||
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
||||
function PasskeySection() {
|
||||
const { t } = useTranslation();
|
||||
const user = useUser({ or: "throw" });
|
||||
const stackApp = 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] = 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__ */ jsx(Fragment, { children: /* @__PURE__ */ jsx(Section, { title: t("Passkey"), description: hasPasskey ? t("Passkey registered") : t("Register a passkey"), children: /* @__PURE__ */ jsxs("div", { className: "flex md:justify-end gap-2", children: [
|
||||
!hasValidEmail && /* @__PURE__ */ jsx(Typography, { variant: "secondary", type: "label", children: t("To enable Passkey sign-in, please add a verified sign-in email.") }),
|
||||
hasValidEmail && hasPasskey && isLastAuth && /* @__PURE__ */ jsx(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__ */ jsx("div", { children: /* @__PURE__ */ jsx(Button, { onClick: handleAddNewPasskey, variant: "secondary", children: t("Add new passkey") }) }),
|
||||
hasValidEmail && hasPasskey && !isLastAuth && !showConfirmationModal && /* @__PURE__ */ jsx(
|
||||
Button,
|
||||
{
|
||||
variant: "secondary",
|
||||
onClick: () => setShowConfirmationModal(true),
|
||||
children: t("Delete Passkey")
|
||||
}
|
||||
),
|
||||
hasValidEmail && hasPasskey && !isLastAuth && showConfirmationModal && /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-2", children: [
|
||||
/* @__PURE__ */ jsx(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__ */ jsxs("div", { className: "flex gap-2", children: [
|
||||
/* @__PURE__ */ jsx(
|
||||
Button,
|
||||
{
|
||||
variant: "destructive",
|
||||
onClick: handleDeletePasskey,
|
||||
children: t("Disable")
|
||||
}
|
||||
),
|
||||
/* @__PURE__ */ jsx(
|
||||
Button,
|
||||
{
|
||||
variant: "secondary",
|
||||
onClick: () => setShowConfirmationModal(false),
|
||||
children: t("Cancel")
|
||||
}
|
||||
)
|
||||
] })
|
||||
] })
|
||||
] }) }) });
|
||||
}
|
||||
export {
|
||||
PasskeySection
|
||||
};
|
||||
//# sourceMappingURL=passkey-section.js.map
|
||||
File diff suppressed because one or more lines are too long
|
|
@ -0,0 +1,146 @@
|
|||
// src/components-page/account-settings/email-and-auth/password-section.tsx
|
||||
import { yupResolver } from "@hookform/resolvers/yup";
|
||||
import { getPasswordError } from "@stackframe/stack-shared/dist/helpers/password";
|
||||
import { passwordSchema as schemaFieldsPasswordSchema, yupObject, yupString } from "@stackframe/stack-shared/dist/schema-fields";
|
||||
import { runAsynchronously, runAsynchronouslyWithAlert } from "@stackframe/stack-shared/dist/utils/promises";
|
||||
import { Button, Input, Label, PasswordInput, Typography } from "@stackframe/stack-ui";
|
||||
import { useState } from "react";
|
||||
import { useForm } from "react-hook-form";
|
||||
import * as yup from "yup";
|
||||
import { useStackApp } from "../../..";
|
||||
import { FormWarningText } from "../../../components/elements/form-warning";
|
||||
import { useUser } from "../../../lib/hooks";
|
||||
import { useTranslation } from "../../../lib/translations";
|
||||
import { Section } from "../section";
|
||||
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
||||
function PasswordSection() {
|
||||
const { t } = useTranslation();
|
||||
const user = useUser({ or: "throw" });
|
||||
const contactChannels = user.useContactChannels();
|
||||
const [changingPassword, setChangingPassword] = useState(false);
|
||||
const [loading, setLoading] = useState(false);
|
||||
const project = useStackApp().useProject();
|
||||
const passwordSchema = yupObject({
|
||||
oldPassword: user.hasPassword ? schemaFieldsPasswordSchema.defined().nonEmpty(t("Please enter your old password")) : yupString(),
|
||||
newPassword: schemaFieldsPasswordSchema.defined().nonEmpty(t("Please enter your password")).test({
|
||||
name: "is-valid-password",
|
||||
test: (value, ctx) => {
|
||||
const error = getPasswordError(value);
|
||||
if (error) {
|
||||
return ctx.createError({ message: error.message });
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}),
|
||||
newPasswordRepeat: 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 } = useForm({
|
||||
resolver: 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__ */ jsx(
|
||||
Section,
|
||||
{
|
||||
title: t("Password"),
|
||||
description: user.hasPassword ? t("Update your password") : t("Set a password for your account"),
|
||||
children: /* @__PURE__ */ jsx("div", { className: "flex flex-col gap-4", children: !changingPassword ? hasValidEmail ? /* @__PURE__ */ jsx(
|
||||
Button,
|
||||
{
|
||||
variant: "secondary",
|
||||
onClick: () => setChangingPassword(true),
|
||||
children: user.hasPassword ? t("Update password") : t("Set password")
|
||||
}
|
||||
) : /* @__PURE__ */ jsx(Typography, { variant: "secondary", type: "label", children: t("To set a password, please add a sign-in email.") }) : /* @__PURE__ */ jsxs(
|
||||
"form",
|
||||
{
|
||||
onSubmit: (e) => runAsynchronouslyWithAlert(handleSubmit(onSubmit)(e)),
|
||||
noValidate: true,
|
||||
children: [
|
||||
user.hasPassword && /* @__PURE__ */ jsxs(Fragment, { children: [
|
||||
/* @__PURE__ */ jsx(Label, { htmlFor: "old-password", className: "mb-1", children: t("Old password") }),
|
||||
/* @__PURE__ */ jsx(
|
||||
Input,
|
||||
{
|
||||
id: "old-password",
|
||||
type: "password",
|
||||
autoComplete: "current-password",
|
||||
...register("oldPassword")
|
||||
}
|
||||
),
|
||||
/* @__PURE__ */ jsx(FormWarningText, { text: errors.oldPassword?.message?.toString() })
|
||||
] }),
|
||||
/* @__PURE__ */ jsx(Label, { htmlFor: "new-password", className: "mt-4 mb-1", children: t("New password") }),
|
||||
/* @__PURE__ */ jsx(
|
||||
PasswordInput,
|
||||
{
|
||||
id: "new-password",
|
||||
autoComplete: "new-password",
|
||||
...registerPassword,
|
||||
onChange: (e) => {
|
||||
clearErrors("newPassword");
|
||||
clearErrors("newPasswordRepeat");
|
||||
runAsynchronously(registerPassword.onChange(e));
|
||||
}
|
||||
}
|
||||
),
|
||||
/* @__PURE__ */ jsx(FormWarningText, { text: errors.newPassword?.message?.toString() }),
|
||||
/* @__PURE__ */ jsx(Label, { htmlFor: "repeat-password", className: "mt-4 mb-1", children: t("Repeat new password") }),
|
||||
/* @__PURE__ */ jsx(
|
||||
PasswordInput,
|
||||
{
|
||||
id: "repeat-password",
|
||||
autoComplete: "new-password",
|
||||
...registerPasswordRepeat,
|
||||
onChange: (e) => {
|
||||
clearErrors("newPassword");
|
||||
clearErrors("newPasswordRepeat");
|
||||
runAsynchronously(registerPasswordRepeat.onChange(e));
|
||||
}
|
||||
}
|
||||
),
|
||||
/* @__PURE__ */ jsx(FormWarningText, { text: errors.newPasswordRepeat?.message?.toString() }),
|
||||
/* @__PURE__ */ jsxs("div", { className: "mt-6 flex gap-4", children: [
|
||||
/* @__PURE__ */ jsx(Button, { type: "submit", loading, children: user.hasPassword ? t("Update Password") : t("Set Password") }),
|
||||
/* @__PURE__ */ jsx(
|
||||
Button,
|
||||
{
|
||||
variant: "secondary",
|
||||
onClick: () => {
|
||||
setChangingPassword(false);
|
||||
reset();
|
||||
},
|
||||
children: t("Cancel")
|
||||
}
|
||||
)
|
||||
] })
|
||||
]
|
||||
}
|
||||
) })
|
||||
}
|
||||
);
|
||||
}
|
||||
export {
|
||||
PasswordSection
|
||||
};
|
||||
//# sourceMappingURL=password-section.js.map
|
||||
File diff suppressed because one or more lines are too long
Loading…
Add table
Add a link
Reference in a new issue