@stackframe/stack 2.4.12 → 2.4.15
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +25 -0
- package/dist/components/credential-sign-in.js +45 -65
- package/dist/components/credential-sign-in.js.map +1 -1
- package/dist/components/credential-sign-up.js +74 -98
- package/dist/components/credential-sign-up.js.map +1 -1
- package/dist/components/forgot-password.js +41 -38
- package/dist/components/forgot-password.js.map +1 -1
- package/dist/components/magic-link-sign-in.js +37 -41
- package/dist/components/magic-link-sign-in.js.map +1 -1
- package/dist/components/oauth-button.js +47 -53
- package/dist/components/oauth-button.js.map +1 -1
- package/dist/components/password-field.js +6 -8
- package/dist/components/password-field.js.map +1 -1
- package/dist/components/password-reset-inner.js +61 -56
- package/dist/components/password-reset-inner.js.map +1 -1
- package/dist/components/redirect-message-card.js +1 -2
- package/dist/components/redirect-message-card.js.map +1 -1
- package/dist/components/user-avatar.d.mts +1 -0
- package/dist/components/user-avatar.d.ts +1 -0
- package/dist/components/user-avatar.js +7 -5
- package/dist/components/user-avatar.js.map +1 -1
- package/dist/components/user-button.js +14 -18
- package/dist/components/user-button.js.map +1 -1
- package/dist/components-core/button.d.mts +1 -0
- package/dist/components-core/button.d.ts +1 -0
- package/dist/components-core/button.js +31 -14
- package/dist/components-core/button.js.map +1 -1
- package/dist/components-core/card.js +3 -3
- package/dist/components-core/card.js.map +1 -1
- package/dist/components-core/index.d.mts +1 -1
- package/dist/components-core/index.d.ts +1 -1
- package/dist/components-core/input.js +10 -6
- package/dist/components-core/input.js.map +1 -1
- package/dist/components-core/label.js +2 -3
- package/dist/components-core/label.js.map +1 -1
- package/dist/components-core/tabs.js +9 -5
- package/dist/components-core/tabs.js.map +1 -1
- package/dist/components-page/account-settings.js +8 -8
- package/dist/components-page/account-settings.js.map +1 -1
- package/dist/components-page/auth-page.js +1 -1
- package/dist/components-page/auth-page.js.map +1 -1
- package/dist/components-page/password-reset.js.map +1 -1
- package/dist/components-page/stack-handler.d.mts +1 -0
- package/dist/components-page/stack-handler.d.ts +1 -0
- package/dist/esm/components/credential-sign-in.js +45 -65
- package/dist/esm/components/credential-sign-in.js.map +1 -1
- package/dist/esm/components/credential-sign-up.js +74 -98
- package/dist/esm/components/credential-sign-up.js.map +1 -1
- package/dist/esm/components/forgot-password.js +41 -38
- package/dist/esm/components/forgot-password.js.map +1 -1
- package/dist/esm/components/magic-link-sign-in.js +37 -41
- package/dist/esm/components/magic-link-sign-in.js.map +1 -1
- package/dist/esm/components/oauth-button.js +47 -53
- package/dist/esm/components/oauth-button.js.map +1 -1
- package/dist/esm/components/password-field.js +6 -8
- package/dist/esm/components/password-field.js.map +1 -1
- package/dist/esm/components/password-reset-inner.js +61 -56
- package/dist/esm/components/password-reset-inner.js.map +1 -1
- package/dist/esm/components/redirect-message-card.js +1 -2
- package/dist/esm/components/redirect-message-card.js.map +1 -1
- package/dist/esm/components/user-avatar.js +7 -5
- package/dist/esm/components/user-avatar.js.map +1 -1
- package/dist/esm/components/user-button.js +26 -19
- package/dist/esm/components/user-button.js.map +1 -1
- package/dist/esm/components-core/button.js +33 -16
- package/dist/esm/components-core/button.js.map +1 -1
- package/dist/esm/components-core/card.js +3 -3
- package/dist/esm/components-core/card.js.map +1 -1
- package/dist/esm/components-core/input.js +11 -7
- package/dist/esm/components-core/input.js.map +1 -1
- package/dist/esm/components-core/label.js +2 -3
- package/dist/esm/components-core/label.js.map +1 -1
- package/dist/esm/components-core/tabs.js +10 -6
- package/dist/esm/components-core/tabs.js.map +1 -1
- package/dist/esm/components-page/account-settings.js +8 -8
- package/dist/esm/components-page/account-settings.js.map +1 -1
- package/dist/esm/components-page/auth-page.js +1 -1
- package/dist/esm/components-page/auth-page.js.map +1 -1
- package/dist/esm/components-page/password-reset.js.map +1 -1
- package/dist/esm/lib/stack-app.js +18 -1
- package/dist/esm/lib/stack-app.js.map +1 -1
- package/dist/esm/utils/constants.js +10 -10
- package/dist/esm/utils/constants.js.map +1 -1
- package/dist/index.d.mts +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/lib/hooks.d.mts +1 -0
- package/dist/lib/hooks.d.ts +1 -0
- package/dist/lib/stack-app.d.mts +6 -1
- package/dist/lib/stack-app.d.ts +6 -1
- package/dist/lib/stack-app.js +18 -1
- package/dist/lib/stack-app.js.map +1 -1
- package/dist/providers/component-provider.d.mts +2 -2
- package/dist/providers/component-provider.d.ts +2 -2
- package/dist/providers/stack-provider-client.d.mts +1 -0
- package/dist/providers/stack-provider-client.d.ts +1 -0
- package/dist/providers/stack-provider.d.mts +1 -0
- package/dist/providers/stack-provider.d.ts +1 -0
- package/dist/utils/constants.d.mts +26 -26
- package/dist/utils/constants.d.ts +26 -26
- package/dist/utils/constants.js +12 -12
- package/dist/utils/constants.js.map +1 -1
- package/package.json +9 -6
- package/dist/components-core/loading-indicator.d.mts +0 -11
- package/dist/components-core/loading-indicator.d.ts +0 -11
- package/dist/components-core/loading-indicator.js +0 -62
- package/dist/components-core/loading-indicator.js.map +0 -1
- package/dist/esm/components-core/loading-indicator.js +0 -31
- package/dist/esm/components-core/loading-indicator.js.map +0 -1
|
@@ -58,7 +58,7 @@ function AuthPage({
|
|
|
58
58
|
const enableSeparator = (project.credentialEnabled || project.magicLinkEnabled) && project.oauthProviders.filter((p) => p.enabled).length > 0;
|
|
59
59
|
return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_card_frame.default, { fullPage, children: [
|
|
60
60
|
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { style: { textAlign: "center", marginBottom: "1.5rem" }, children: [
|
|
61
|
-
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_components_core.Text, { size: "xl", as: "h2", children: type === "sign-in" ? "Sign in to your account" : "Create a new account" }),
|
|
61
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_components_core.Text, { size: "xl", as: "h2", style: { fontWeight: 500 }, children: type === "sign-in" ? "Sign in to your account" : "Create a new account" }),
|
|
62
62
|
type === "sign-in" ? /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_components_core.Text, { children: [
|
|
63
63
|
"Don't have an account? ",
|
|
64
64
|
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_components_core.Link, { href: stackApp.urls.signUp, children: "Sign up" })
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/components-page/auth-page.tsx"],"sourcesContent":["'use client';\n\nimport CredentialSignIn from '../components/credential-sign-in';\nimport SeparatorWithText from '../components/separator-with-text';\nimport OAuthGroup from '../components/oauth-group';\nimport CardFrame from '../components/card-frame';\nimport { useUser, useStackApp, CredentialSignUp } from '..';\nimport RedirectMessageCard from '../components/redirect-message-card';\nimport { Link, Tabs, TabsContent, TabsList, TabsTrigger, Text } from \"../components-core\";\nimport MagicLinkSignIn from '../components/magic-link-sign-in';\nimport { ClientProjectJson } from \"@stackframe/stack-shared\";\n\nexport default function AuthPage({ \n fullPage=false,\n type,\n mockProject,\n}: { \n fullPage?: boolean, \n type: 'sign-in' | 'sign-up',\n mockProject?: ClientProjectJson,\n}) {\n const stackApp = useStackApp();\n const user = useUser();\n const project = mockProject || stackApp.useProject();\n\n if (user && !mockProject) {\n return <RedirectMessageCard type='signedIn' fullPage={fullPage} />;\n }\n\n const enableSeparator = (project.credentialEnabled || project.magicLinkEnabled) && project.oauthProviders.filter(p => p.enabled).length > 0;\n\n return (\n <CardFrame fullPage={fullPage}>\n <div style={{ textAlign: 'center', marginBottom: '1.5rem' }}>\n <Text size=\"xl\" as='h2'
|
|
1
|
+
{"version":3,"sources":["../../src/components-page/auth-page.tsx"],"sourcesContent":["'use client';\n\nimport CredentialSignIn from '../components/credential-sign-in';\nimport SeparatorWithText from '../components/separator-with-text';\nimport OAuthGroup from '../components/oauth-group';\nimport CardFrame from '../components/card-frame';\nimport { useUser, useStackApp, CredentialSignUp } from '..';\nimport RedirectMessageCard from '../components/redirect-message-card';\nimport { Link, Tabs, TabsContent, TabsList, TabsTrigger, Text } from \"../components-core\";\nimport MagicLinkSignIn from '../components/magic-link-sign-in';\nimport { ClientProjectJson } from \"@stackframe/stack-shared\";\n\nexport default function AuthPage({ \n fullPage=false,\n type,\n mockProject,\n}: { \n fullPage?: boolean, \n type: 'sign-in' | 'sign-up',\n mockProject?: ClientProjectJson,\n}) {\n const stackApp = useStackApp();\n const user = useUser();\n const project = mockProject || stackApp.useProject();\n\n if (user && !mockProject) {\n return <RedirectMessageCard type='signedIn' fullPage={fullPage} />;\n }\n\n const enableSeparator = (project.credentialEnabled || project.magicLinkEnabled) && project.oauthProviders.filter(p => p.enabled).length > 0;\n\n return (\n <CardFrame fullPage={fullPage}>\n <div style={{ textAlign: 'center', marginBottom: '1.5rem' }}>\n <Text size=\"xl\" as='h2' style={{ fontWeight: 500 }}>\n {type === 'sign-in' ? 'Sign in to your account' : 'Create a new account'}\n </Text>\n {type === 'sign-in' ? (\n <Text>\n {\"Don't have an account? \"}\n <Link href={stackApp.urls.signUp}>\n Sign up\n </Link>\n </Text>\n ) : (\n <Text>\n {\"Already have an account? \"}\n <Link href={stackApp.urls.signIn}>\n Sign in\n </Link>\n </Text>\n )}\n </div>\n <OAuthGroup type={type} mockProject={mockProject} />\n {enableSeparator && <SeparatorWithText text={'Or continue with'} />}\n {project.credentialEnabled && project.magicLinkEnabled ? (\n <Tabs defaultValue='magic-link'>\n <TabsList>\n <TabsTrigger value='magic-link'>Magic Link</TabsTrigger>\n <TabsTrigger value='password'>Password</TabsTrigger>\n </TabsList>\n <TabsContent value='magic-link'>\n <MagicLinkSignIn/>\n </TabsContent>\n <TabsContent value='password'>\n {type === 'sign-up' ? <CredentialSignUp/> : <CredentialSignIn/>}\n </TabsContent>\n </Tabs>\n ) : project.credentialEnabled ? (\n type === 'sign-up' ? <CredentialSignUp/> : <CredentialSignIn/>\n ) : project.magicLinkEnabled ? (\n <MagicLinkSignIn/>\n ) : null}\n </CardFrame>\n );\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;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sBAAQ;AAAA,SACxC;AAAA,MACA,4CAAC,sCAAY,OAAM,cACjB,sDAAC,0BAAAC,SAAA,EAAe,GAClB;AAAA,MACA,4CAAC,sCAAY,OAAM,YAChB,mBAAS,YAAY,4CAAC,6BAAgB,IAAK,4CAAC,0BAAAC,SAAA,EAAgB,GAC/D;AAAA,OACF,IACE,QAAQ,oBACV,SAAS,YAAY,4CAAC,6BAAgB,IAAK,4CAAC,0BAAAA,SAAA,EAAgB,IAC1D,QAAQ,mBACV,4CAAC,0BAAAD,SAAA,EAAe,IACd;AAAA,KACN;AAEJ;","names":["RedirectMessageCard","CardFrame","OAuthGroup","SeparatorWithText","MagicLinkSignIn","CredentialSignIn"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/components-page/password-reset.tsx"],"sourcesContent":["'use client';\n\nimport MessageCard from \"../components/message-card\";\nimport { StackClientApp, useStackApp } from \"..\";\nimport { use } from \"react\";\nimport PasswordResetInner from \"../components/password-reset-inner\";\nimport { cacheFunction } from \"@stackframe/stack-shared/dist/utils/caches\";\nimport { Text } from \"../components-core\";\nimport { KnownErrors } from \"@stackframe/stack-shared\";\
|
|
1
|
+
{"version":3,"sources":["../../src/components-page/password-reset.tsx"],"sourcesContent":["'use client';\n\nimport MessageCard from \"../components/message-card\";\nimport { StackClientApp, useStackApp } from \"..\";\nimport { use } from \"react\";\nimport PasswordResetInner from \"../components/password-reset-inner\";\nimport { cacheFunction } from \"@stackframe/stack-shared/dist/utils/caches\";\nimport { Text } from \"../components-core\";\nimport { KnownErrors } from \"@stackframe/stack-shared\";\n\nconst cachedVerifyPasswordResetCode = cacheFunction(async (stackApp: StackClientApp<true>, code: string) => {\n return await stackApp.verifyPasswordResetCode(code);\n});\n\nexport default function PasswordReset({\n searchParams,\n fullPage = false,\n}: { \n searchParams?: Record<string, string>,\n fullPage?: boolean, \n}) {\n const stackApp = useStackApp();\n\n const invalidJsx = (\n <MessageCard title=\"Invalid Password Reset Link\" fullPage={fullPage}>\n <Text>Please double check if you have the correct password reset link.</Text>\n </MessageCard>\n );\n\n const expiredJsx = (\n <MessageCard title=\"Expired Password Reset Link\" fullPage={fullPage}>\n <Text>Your password reset link has expired. Please request a new password reset link from the login page.</Text>\n </MessageCard>\n );\n\n const usedJsx = (\n <MessageCard title=\"Used Password Reset Link\" fullPage={fullPage}>\n <Text>This password reset link has already been used. If you need to reset your password again, please request a new password reset link from the login page.</Text>\n </MessageCard>\n );\n\n const code = searchParams?.code;\n if (!code) {\n return invalidJsx;\n }\n\n const error = use(cachedVerifyPasswordResetCode(stackApp, code));\n \n if (error instanceof KnownErrors.PasswordResetCodeNotFound) {\n return invalidJsx;\n } else if (error instanceof KnownErrors.PasswordResetCodeExpired) {\n return expiredJsx;\n } else if (error instanceof KnownErrors.PasswordResetCodeAlreadyUsed) {\n return usedJsx;\n } else if (error) {\n throw error;\n }\n\n return <PasswordResetInner code={code} fullPage={fullPage} />;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAEA,0BAAwB;AACxB,eAA4C;AAC5C,mBAAoB;AACpB,kCAA+B;AAC/B,oBAA8B;AAC9B,6BAAqB;AACrB,0BAA4B;AAiBtB;AAfN,IAAM,oCAAgC,6BAAc,OAAO,UAAgC,SAAiB;AAC1G,SAAO,MAAM,SAAS,wBAAwB,IAAI;AACpD,CAAC;AAEc,SAAR,cAA+B;AAAA,EACpC;AAAA,EACA,WAAW;AACb,GAGG;AACD,QAAM,eAAW,sBAAY;AAE7B,QAAM,aACJ,4CAAC,oBAAAA,SAAA,EAAY,OAAM,+BAA8B,UAC/C,sDAAC,+BAAK,8EAAgE,GACxE;AAGF,QAAM,aACJ,4CAAC,oBAAAA,SAAA,EAAY,OAAM,+BAA8B,UAC/C,sDAAC,+BAAK,iHAAmG,GAC3G;AAGF,QAAM,UACJ,4CAAC,oBAAAA,SAAA,EAAY,OAAM,4BAA2B,UAC5C,sDAAC,+BAAK,qKAAuJ,GAC/J;AAGF,QAAM,OAAO,cAAc;AAC3B,MAAI,CAAC,MAAM;AACT,WAAO;AAAA,EACT;AAEA,QAAM,YAAQ,kBAAI,8BAA8B,UAAU,IAAI,CAAC;AAE/D,MAAI,iBAAiB,gCAAY,2BAA2B;AAC1D,WAAO;AAAA,EACT,WAAW,iBAAiB,gCAAY,0BAA0B;AAChE,WAAO;AAAA,EACT,WAAW,iBAAiB,gCAAY,8BAA8B;AACpE,WAAO;AAAA,EACT,WAAW,OAAO;AAChB,UAAM;AAAA,EACR;AAEA,SAAO,4CAAC,4BAAAC,SAAA,EAAmB,MAAY,UAAoB;AAC7D;","names":["MessageCard","PasswordResetInner"]}
|
|
@@ -5,6 +5,7 @@ import '@stackframe/stack-shared/dist/interface/clientInterface';
|
|
|
5
5
|
import '@stackframe/stack-shared/dist/utils/json';
|
|
6
6
|
import '@stackframe/stack-shared/dist/interface/adminInterface';
|
|
7
7
|
import '@stackframe/stack-shared/dist/interface/serverInterface';
|
|
8
|
+
import '@stackframe/stack-shared/dist/interface/crud/email-templates';
|
|
8
9
|
|
|
9
10
|
declare function StackHandler<HasTokenStore extends boolean>({ app, params: { stack }, searchParams, }: {
|
|
10
11
|
app: StackServerApp<HasTokenStore>;
|
|
@@ -5,6 +5,7 @@ import '@stackframe/stack-shared/dist/interface/clientInterface';
|
|
|
5
5
|
import '@stackframe/stack-shared/dist/utils/json';
|
|
6
6
|
import '@stackframe/stack-shared/dist/interface/adminInterface';
|
|
7
7
|
import '@stackframe/stack-shared/dist/interface/serverInterface';
|
|
8
|
+
import '@stackframe/stack-shared/dist/interface/crud/email-templates';
|
|
8
9
|
|
|
9
10
|
declare function StackHandler<HasTokenStore extends boolean>({ app, params: { stack }, searchParams, }: {
|
|
10
11
|
app: StackServerApp<HasTokenStore>;
|
|
@@ -2,80 +2,60 @@
|
|
|
2
2
|
"use client";
|
|
3
3
|
|
|
4
4
|
// src/components/credential-sign-in.tsx
|
|
5
|
-
import {
|
|
5
|
+
import { useForm } from "react-hook-form";
|
|
6
|
+
import { yupResolver } from "@hookform/resolvers/yup";
|
|
7
|
+
import * as yup from "yup";
|
|
6
8
|
import FormWarningText from "./form-warning";
|
|
7
9
|
import PasswordField from "./password-field";
|
|
8
|
-
import { validateEmail } from "../utils/email";
|
|
9
10
|
import { useStackApp } from "..";
|
|
10
11
|
import { Button, Input, Label, Link } from "../components-core";
|
|
11
|
-
import {
|
|
12
|
+
import { runAsynchronously } from "@stackframe/stack-shared/dist/utils/promises";
|
|
12
13
|
import { jsx, jsxs } from "react/jsx-runtime";
|
|
14
|
+
var schema = yup.object().shape({
|
|
15
|
+
email: yup.string().email("Please enter a valid email").required("Please enter your email"),
|
|
16
|
+
password: yup.string().required("Please enter your password")
|
|
17
|
+
});
|
|
13
18
|
function CredentialSignIn() {
|
|
14
|
-
const
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
const [passwordError, setPasswordError] = useState("");
|
|
19
|
+
const { register, handleSubmit, setError, formState: { errors }, clearErrors } = useForm({
|
|
20
|
+
resolver: yupResolver(schema)
|
|
21
|
+
});
|
|
18
22
|
const app = useStackApp();
|
|
19
|
-
const onSubmit = async () => {
|
|
20
|
-
|
|
21
|
-
setEmailError("Please enter your email");
|
|
22
|
-
return;
|
|
23
|
-
}
|
|
24
|
-
if (!validateEmail(email)) {
|
|
25
|
-
setEmailError("Please enter a valid email");
|
|
26
|
-
return;
|
|
27
|
-
}
|
|
28
|
-
if (!password) {
|
|
29
|
-
setPasswordError("Please enter your password");
|
|
30
|
-
return;
|
|
31
|
-
}
|
|
23
|
+
const onSubmit = async (data) => {
|
|
24
|
+
const { email, password } = data;
|
|
32
25
|
const error = await app.signInWithCredential({ email, password });
|
|
33
|
-
|
|
34
|
-
setPasswordError("Wrong email or password");
|
|
35
|
-
} else if (error) {
|
|
36
|
-
setEmailError(`An error occurred. ${error.message}`);
|
|
37
|
-
}
|
|
26
|
+
setError("email", { type: "manual", message: error?.message });
|
|
38
27
|
};
|
|
39
|
-
return /* @__PURE__ */ jsxs(
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
/* @__PURE__ */ jsx(
|
|
71
|
-
Button,
|
|
72
|
-
{
|
|
73
|
-
style: { marginTop: "1.5rem" },
|
|
74
|
-
onClick: onSubmit,
|
|
75
|
-
children: "Sign In"
|
|
76
|
-
}
|
|
77
|
-
)
|
|
78
|
-
] });
|
|
28
|
+
return /* @__PURE__ */ jsxs(
|
|
29
|
+
"form",
|
|
30
|
+
{
|
|
31
|
+
style: { display: "flex", flexDirection: "column", alignItems: "stretch" },
|
|
32
|
+
onSubmit: (e) => runAsynchronously(handleSubmit(onSubmit)(e)),
|
|
33
|
+
noValidate: true,
|
|
34
|
+
children: [
|
|
35
|
+
/* @__PURE__ */ jsx(Label, { htmlFor: "email", children: "Email" }),
|
|
36
|
+
/* @__PURE__ */ jsx(
|
|
37
|
+
Input,
|
|
38
|
+
{
|
|
39
|
+
id: "email",
|
|
40
|
+
type: "email",
|
|
41
|
+
...register("email")
|
|
42
|
+
}
|
|
43
|
+
),
|
|
44
|
+
/* @__PURE__ */ jsx(FormWarningText, { text: errors.email?.message?.toString() }),
|
|
45
|
+
/* @__PURE__ */ jsx(Label, { htmlFor: "password", style: { marginTop: "1rem" }, children: "Password" }),
|
|
46
|
+
/* @__PURE__ */ jsx(
|
|
47
|
+
PasswordField,
|
|
48
|
+
{
|
|
49
|
+
id: "password",
|
|
50
|
+
...register("password")
|
|
51
|
+
}
|
|
52
|
+
),
|
|
53
|
+
/* @__PURE__ */ jsx(FormWarningText, { text: errors.password?.message?.toString() }),
|
|
54
|
+
/* @__PURE__ */ jsx(Link, { href: app.urls.forgotPassword, size: "sm", style: { marginTop: "0.5rem" }, children: "Forgot password?" }),
|
|
55
|
+
/* @__PURE__ */ jsx(Button, { type: "submit", style: { marginTop: "1.5rem" }, children: "Sign In" })
|
|
56
|
+
]
|
|
57
|
+
}
|
|
58
|
+
);
|
|
79
59
|
}
|
|
80
60
|
export {
|
|
81
61
|
CredentialSignIn as default
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/components/credential-sign-in.tsx"],"sourcesContent":["'use client';\n\nimport {
|
|
1
|
+
{"version":3,"sources":["../../../src/components/credential-sign-in.tsx"],"sourcesContent":["'use client';\n\nimport { useForm } from \"react-hook-form\";\nimport { yupResolver } from \"@hookform/resolvers/yup\";\nimport * as yup from \"yup\";\nimport FormWarningText from \"./form-warning\";\nimport PasswordField from \"./password-field\";\nimport { useStackApp } from \"..\";\nimport { Button, Input, Label, Link } from \"../components-core\";\nimport { runAsynchronously } from \"@stackframe/stack-shared/dist/utils/promises\";\n\nconst schema = yup.object().shape({\n email: yup.string().email('Please enter a valid email').required('Please enter your email'),\n password: yup.string().required('Please enter your password')\n});\n\nexport default function CredentialSignIn() {\n const { register, handleSubmit, setError, formState: { errors }, clearErrors } = useForm({\n resolver: yupResolver(schema)\n });\n const app = useStackApp();\n\n const onSubmit = async (data: yup.InferType<typeof schema>) => {\n const { email, password } = data;\n\n const error = await app.signInWithCredential({ email, password });\n setError('email', { type: 'manual', message: error?.message });\n };\n\n return (\n <form \n style={{ display: 'flex', flexDirection: 'column', alignItems: 'stretch' }} \n onSubmit={e => runAsynchronously(handleSubmit(onSubmit)(e))}\n noValidate\n >\n <Label htmlFor=\"email\">Email</Label>\n <Input\n id=\"email\"\n type=\"email\"\n {...register('email')}\n />\n <FormWarningText text={errors.email?.message?.toString()} />\n\n <Label htmlFor=\"password\" style={{ marginTop: '1rem' }}>Password</Label>\n <PasswordField\n id=\"password\"\n {...register('password')}\n />\n <FormWarningText text={errors.password?.message?.toString()} />\n\n <Link href={app.urls.forgotPassword} size='sm' style={{ marginTop: '0.5rem' }}>\n Forgot password?\n </Link>\n\n <Button type=\"submit\" style={{ marginTop: '1.5rem' }}>\n Sign In\n </Button>\n </form>\n );\n}\n"],"mappings":";;;AAEA,SAAS,eAAe;AACxB,SAAS,mBAAmB;AAC5B,YAAY,SAAS;AACrB,OAAO,qBAAqB;AAC5B,OAAO,mBAAmB;AAC1B,SAAS,mBAAmB;AAC5B,SAAS,QAAQ,OAAO,OAAO,YAAY;AAC3C,SAAS,yBAAyB;AAqB9B,SAKE,KALF;AAnBJ,IAAM,SAAa,WAAO,EAAE,MAAM;AAAA,EAChC,OAAW,WAAO,EAAE,MAAM,4BAA4B,EAAE,SAAS,yBAAyB;AAAA,EAC1F,UAAc,WAAO,EAAE,SAAS,4BAA4B;AAC9D,CAAC;AAEc,SAAR,mBAAoC;AACzC,QAAM,EAAE,UAAU,cAAc,UAAU,WAAW,EAAE,OAAO,GAAG,YAAY,IAAI,QAAQ;AAAA,IACvF,UAAU,YAAY,MAAM;AAAA,EAC9B,CAAC;AACD,QAAM,MAAM,YAAY;AAExB,QAAM,WAAW,OAAO,SAAuC;AAC7D,UAAM,EAAE,OAAO,SAAS,IAAI;AAE5B,UAAM,QAAQ,MAAM,IAAI,qBAAqB,EAAE,OAAO,SAAS,CAAC;AAChE,aAAS,SAAS,EAAE,MAAM,UAAU,SAAS,OAAO,QAAQ,CAAC;AAAA,EAC/D;AAEA,SACE;AAAA,IAAC;AAAA;AAAA,MACC,OAAO,EAAE,SAAS,QAAQ,eAAe,UAAU,YAAY,UAAU;AAAA,MACzE,UAAU,OAAK,kBAAkB,aAAa,QAAQ,EAAE,CAAC,CAAC;AAAA,MAC1D,YAAU;AAAA,MAEV;AAAA,4BAAC,SAAM,SAAQ,SAAQ,mBAAK;AAAA,QAC5B;AAAA,UAAC;AAAA;AAAA,YACC,IAAG;AAAA,YACH,MAAK;AAAA,YACJ,GAAG,SAAS,OAAO;AAAA;AAAA,QACtB;AAAA,QACA,oBAAC,mBAAgB,MAAM,OAAO,OAAO,SAAS,SAAS,GAAG;AAAA,QAE1D,oBAAC,SAAM,SAAQ,YAAW,OAAO,EAAE,WAAW,OAAO,GAAG,sBAAQ;AAAA,QAChE;AAAA,UAAC;AAAA;AAAA,YACC,IAAG;AAAA,YACF,GAAG,SAAS,UAAU;AAAA;AAAA,QACzB;AAAA,QACA,oBAAC,mBAAgB,MAAM,OAAO,UAAU,SAAS,SAAS,GAAG;AAAA,QAE7D,oBAAC,QAAK,MAAM,IAAI,KAAK,gBAAgB,MAAK,MAAK,OAAO,EAAE,WAAW,SAAS,GAAG,8BAE/E;AAAA,QAEA,oBAAC,UAAO,MAAK,UAAS,OAAO,EAAE,WAAW,SAAS,GAAG,qBAEtD;AAAA;AAAA;AAAA,EACF;AAEJ;","names":[]}
|
|
@@ -2,112 +2,88 @@
|
|
|
2
2
|
"use client";
|
|
3
3
|
|
|
4
4
|
// src/components/credential-sign-up.tsx
|
|
5
|
-
import {
|
|
5
|
+
import { useForm } from "react-hook-form";
|
|
6
|
+
import { yupResolver } from "@hookform/resolvers/yup";
|
|
7
|
+
import * as yup from "yup";
|
|
6
8
|
import PasswordField from "./password-field";
|
|
7
9
|
import FormWarningText from "./form-warning";
|
|
8
|
-
import { validateEmail } from "../utils/email";
|
|
9
|
-
import { getPasswordError } from "@stackframe/stack-shared/dist/helpers/password";
|
|
10
10
|
import { useStackApp } from "..";
|
|
11
11
|
import { Label, Input, Button } from "../components-core";
|
|
12
|
-
import {
|
|
12
|
+
import { runAsynchronously } from "@stackframe/stack-shared/dist/utils/promises";
|
|
13
|
+
import { getPasswordError } from "@stackframe/stack-shared/dist/helpers/password";
|
|
13
14
|
import { jsx, jsxs } from "react/jsx-runtime";
|
|
15
|
+
var schema = yup.object().shape({
|
|
16
|
+
email: yup.string().email("Please enter a valid email").required("Please enter your email"),
|
|
17
|
+
password: yup.string().required("Please enter your password").test({
|
|
18
|
+
name: "is-valid-password",
|
|
19
|
+
test: (value, ctx) => {
|
|
20
|
+
const error = getPasswordError(value);
|
|
21
|
+
if (error) {
|
|
22
|
+
return ctx.createError({ message: error.message });
|
|
23
|
+
} else {
|
|
24
|
+
return true;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
}),
|
|
28
|
+
passwordRepeat: yup.string().nullable().oneOf([yup.ref("password"), null], "Passwords do not match").required("Please repeat your password")
|
|
29
|
+
});
|
|
14
30
|
function CredentialSignUp() {
|
|
15
|
-
const
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
const [passwordError, setPasswordError] = useState("");
|
|
19
|
-
const [passwordRepeat, setPasswordRepeat] = useState("");
|
|
20
|
-
const [passwordRepeatError, setPasswordRepeatError] = useState("");
|
|
31
|
+
const { register, handleSubmit, setError, formState: { errors }, clearErrors } = useForm({
|
|
32
|
+
resolver: yupResolver(schema)
|
|
33
|
+
});
|
|
21
34
|
const app = useStackApp();
|
|
22
|
-
const onSubmit = async () => {
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
}
|
|
27
|
-
if (!validateEmail(email)) {
|
|
28
|
-
setEmailError("Please enter a valid email");
|
|
29
|
-
return;
|
|
30
|
-
}
|
|
31
|
-
if (!password) {
|
|
32
|
-
setPasswordError("Please enter your password");
|
|
33
|
-
return;
|
|
34
|
-
}
|
|
35
|
-
if (!passwordRepeat) {
|
|
36
|
-
setPasswordRepeatError("Please repeat your password");
|
|
37
|
-
return;
|
|
38
|
-
}
|
|
39
|
-
if (password !== passwordRepeat) {
|
|
40
|
-
setPasswordRepeatError("Passwords do not match");
|
|
41
|
-
return;
|
|
42
|
-
}
|
|
43
|
-
const passwordError2 = getPasswordError(password);
|
|
44
|
-
if (passwordError2) {
|
|
45
|
-
setPasswordError(passwordError2.message);
|
|
46
|
-
return;
|
|
47
|
-
}
|
|
48
|
-
let error;
|
|
49
|
-
error = await app.signUpWithCredential({ email, password });
|
|
50
|
-
if (error instanceof KnownErrors.UserEmailAlreadyExists) {
|
|
51
|
-
setEmailError("User already exists");
|
|
52
|
-
} else if (error) {
|
|
53
|
-
setEmailError(`An error occurred. ${error.message}`);
|
|
54
|
-
}
|
|
35
|
+
const onSubmit = async (data) => {
|
|
36
|
+
const { email, password } = data;
|
|
37
|
+
const error = await app.signUpWithCredential({ email, password });
|
|
38
|
+
setError("email", { type: "manual", message: error?.message });
|
|
55
39
|
};
|
|
56
|
-
return /* @__PURE__ */ jsxs(
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
Button,
|
|
104
|
-
{
|
|
105
|
-
style: { marginTop: "1.5rem" },
|
|
106
|
-
onClick: onSubmit,
|
|
107
|
-
children: "Sign Up"
|
|
108
|
-
}
|
|
109
|
-
)
|
|
110
|
-
] });
|
|
40
|
+
return /* @__PURE__ */ jsxs(
|
|
41
|
+
"form",
|
|
42
|
+
{
|
|
43
|
+
style: { display: "flex", flexDirection: "column", alignItems: "stretch" },
|
|
44
|
+
onSubmit: (e) => runAsynchronously(handleSubmit(onSubmit)(e)),
|
|
45
|
+
noValidate: true,
|
|
46
|
+
children: [
|
|
47
|
+
/* @__PURE__ */ jsx(Label, { htmlFor: "email", children: "Email" }),
|
|
48
|
+
/* @__PURE__ */ jsx(
|
|
49
|
+
Input,
|
|
50
|
+
{
|
|
51
|
+
id: "email",
|
|
52
|
+
type: "email",
|
|
53
|
+
...register("email")
|
|
54
|
+
}
|
|
55
|
+
),
|
|
56
|
+
/* @__PURE__ */ jsx(FormWarningText, { text: errors.email?.message?.toString() }),
|
|
57
|
+
/* @__PURE__ */ jsx(Label, { htmlFor: "password", style: { marginTop: "1rem" }, children: "Password" }),
|
|
58
|
+
/* @__PURE__ */ jsx(
|
|
59
|
+
PasswordField,
|
|
60
|
+
{
|
|
61
|
+
id: "password",
|
|
62
|
+
...register("password"),
|
|
63
|
+
onChange: (e) => {
|
|
64
|
+
clearErrors("password");
|
|
65
|
+
clearErrors("passwordRepeat");
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
),
|
|
69
|
+
/* @__PURE__ */ jsx(FormWarningText, { text: errors.password?.message?.toString() }),
|
|
70
|
+
/* @__PURE__ */ jsx(Label, { htmlFor: "repeat-password", style: { marginTop: "1rem" }, children: "Repeat Password" }),
|
|
71
|
+
/* @__PURE__ */ jsx(
|
|
72
|
+
PasswordField,
|
|
73
|
+
{
|
|
74
|
+
id: "repeat-password",
|
|
75
|
+
...register("passwordRepeat"),
|
|
76
|
+
onChange: (e) => {
|
|
77
|
+
clearErrors("password");
|
|
78
|
+
clearErrors("passwordRepeat");
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
),
|
|
82
|
+
/* @__PURE__ */ jsx(FormWarningText, { text: errors.passwordRepeat?.message?.toString() }),
|
|
83
|
+
/* @__PURE__ */ jsx(Button, { type: "submit", style: { marginTop: "1.5rem" }, children: "Sign Up" })
|
|
84
|
+
]
|
|
85
|
+
}
|
|
86
|
+
);
|
|
111
87
|
}
|
|
112
88
|
export {
|
|
113
89
|
CredentialSignUp as default
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/components/credential-sign-up.tsx"],"sourcesContent":["'use client';\n\nimport {
|
|
1
|
+
{"version":3,"sources":["../../../src/components/credential-sign-up.tsx"],"sourcesContent":["'use client';\n\nimport { useForm } from \"react-hook-form\";\nimport { yupResolver } from \"@hookform/resolvers/yup\";\nimport * as yup from \"yup\";\nimport PasswordField from \"./password-field\";\nimport FormWarningText from \"./form-warning\";\nimport { useStackApp } from \"..\";\nimport { Label, Input, Button } from \"../components-core\";\nimport { runAsynchronously } from \"@stackframe/stack-shared/dist/utils/promises\";\nimport { getPasswordError } from \"@stackframe/stack-shared/dist/helpers/password\";\n\nconst schema = yup.object().shape({\n email: yup.string().email('Please enter a valid email').required('Please enter your email'),\n password: yup.string().required('Please enter your password').test({\n name: 'is-valid-password',\n test: (value, ctx) => {\n const error = getPasswordError(value);\n if (error) {\n return ctx.createError({ message: error.message });\n } else {\n return true;\n }\n }\n }),\n passwordRepeat: yup.string().nullable().oneOf([yup.ref('password'), null], 'Passwords do not match').required('Please repeat your password')\n});\n\nexport default function CredentialSignUp() {\n const { register, handleSubmit, setError, formState: { errors }, clearErrors } = useForm({\n resolver: yupResolver(schema)\n });\n const app = useStackApp();\n\n const onSubmit = async (data: yup.InferType<typeof schema>) => {\n const { email, password } = data;\n const error = await app.signUpWithCredential({ email, password });\n setError('email', { type: 'manual', message: error?.message });\n };\n\n return (\n <form \n style={{ display: 'flex', flexDirection: 'column', alignItems: 'stretch' }} \n onSubmit={e => runAsynchronously(handleSubmit(onSubmit)(e))}\n noValidate\n >\n <Label htmlFor=\"email\">Email</Label>\n <Input\n id=\"email\"\n type=\"email\"\n {...register('email')}\n />\n <FormWarningText text={errors.email?.message?.toString()} />\n\n <Label htmlFor=\"password\" style={{ marginTop: '1rem' }}>Password</Label>\n <PasswordField\n id=\"password\"\n {...register('password')}\n onChange={(e) => {\n clearErrors('password');\n clearErrors('passwordRepeat');\n }}\n />\n <FormWarningText text={errors.password?.message?.toString()} />\n \n <Label htmlFor=\"repeat-password\" style={{ marginTop: '1rem' }}>Repeat Password</Label>\n <PasswordField\n id=\"repeat-password\"\n {...register('passwordRepeat')}\n onChange={(e) => {\n clearErrors('password');\n clearErrors('passwordRepeat');\n }}\n />\n <FormWarningText text={errors.passwordRepeat?.message?.toString()} />\n\n <Button type=\"submit\" style={{ marginTop: '1.5rem' }}>\n Sign Up\n </Button>\n </form>\n );\n}\n"],"mappings":";;;AAEA,SAAS,eAAe;AACxB,SAAS,mBAAmB;AAC5B,YAAY,SAAS;AACrB,OAAO,mBAAmB;AAC1B,OAAO,qBAAqB;AAC5B,SAAS,mBAAmB;AAC5B,SAAS,OAAO,OAAO,cAAc;AACrC,SAAS,yBAAyB;AAClC,SAAS,wBAAwB;AA+B7B,SAKE,KALF;AA7BJ,IAAM,SAAa,WAAO,EAAE,MAAM;AAAA,EAChC,OAAW,WAAO,EAAE,MAAM,4BAA4B,EAAE,SAAS,yBAAyB;AAAA,EAC1F,UAAc,WAAO,EAAE,SAAS,4BAA4B,EAAE,KAAK;AAAA,IACjE,MAAM;AAAA,IACN,MAAM,CAAC,OAAO,QAAQ;AACpB,YAAM,QAAQ,iBAAiB,KAAK;AACpC,UAAI,OAAO;AACT,eAAO,IAAI,YAAY,EAAE,SAAS,MAAM,QAAQ,CAAC;AAAA,MACnD,OAAO;AACL,eAAO;AAAA,MACT;AAAA,IACF;AAAA,EACF,CAAC;AAAA,EACD,gBAAoB,WAAO,EAAE,SAAS,EAAE,MAAM,CAAK,QAAI,UAAU,GAAG,IAAI,GAAG,wBAAwB,EAAE,SAAS,6BAA6B;AAC7I,CAAC;AAEc,SAAR,mBAAoC;AACzC,QAAM,EAAE,UAAU,cAAc,UAAU,WAAW,EAAE,OAAO,GAAG,YAAY,IAAI,QAAQ;AAAA,IACvF,UAAU,YAAY,MAAM;AAAA,EAC9B,CAAC;AACD,QAAM,M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O,gBAAgB,SAAS,SAAS,GAAG;AAAA,QAEnE,oBAAC,UAAO,MAAK,UAAS,OAAO,EAAE,WAAW,SAAS,GAAG,qBAEtD;AAAA;AAAA;AAAA,EACF;AAEJ;","names":[]}
|
|
@@ -2,53 +2,56 @@
|
|
|
2
2
|
"use client";
|
|
3
3
|
|
|
4
4
|
// src/components/forgot-password.tsx
|
|
5
|
-
import {
|
|
5
|
+
import { useForm } from "react-hook-form";
|
|
6
|
+
import { yupResolver } from "@hookform/resolvers/yup";
|
|
7
|
+
import * as yup from "yup";
|
|
6
8
|
import FormWarningText from "./form-warning";
|
|
7
|
-
import { validateEmail } from "../utils/email";
|
|
8
9
|
import { useStackApp } from "..";
|
|
9
10
|
import { Button, Input, Label } from "../components-core";
|
|
11
|
+
import { runAsynchronously } from "@stackframe/stack-shared/dist/utils/promises";
|
|
10
12
|
import { jsx, jsxs } from "react/jsx-runtime";
|
|
13
|
+
var schema = yup.object().shape({
|
|
14
|
+
email: yup.string().email("Please enter a valid email").required("Please enter your email")
|
|
15
|
+
});
|
|
11
16
|
function ForgotPassword({ onSent }) {
|
|
12
|
-
const
|
|
13
|
-
|
|
17
|
+
const { register, handleSubmit, formState: { errors }, clearErrors } = useForm({
|
|
18
|
+
resolver: yupResolver(schema)
|
|
19
|
+
});
|
|
14
20
|
const stackApp = useStackApp();
|
|
15
|
-
const onSubmit = async () => {
|
|
16
|
-
|
|
17
|
-
setEmailError("Please enter your email");
|
|
18
|
-
return;
|
|
19
|
-
}
|
|
20
|
-
if (!validateEmail(email)) {
|
|
21
|
-
setEmailError("Please enter a valid email");
|
|
22
|
-
return;
|
|
23
|
-
}
|
|
21
|
+
const onSubmit = async (data) => {
|
|
22
|
+
const { email } = data;
|
|
24
23
|
await stackApp.sendForgotPasswordEmail(email);
|
|
25
24
|
onSent?.();
|
|
26
25
|
};
|
|
27
|
-
return /* @__PURE__ */ jsxs(
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
26
|
+
return /* @__PURE__ */ jsxs(
|
|
27
|
+
"form",
|
|
28
|
+
{
|
|
29
|
+
style: { display: "flex", flexDirection: "column", alignItems: "stretch" },
|
|
30
|
+
onSubmit: (e) => runAsynchronously(handleSubmit(onSubmit)(e)),
|
|
31
|
+
noValidate: true,
|
|
32
|
+
children: [
|
|
33
|
+
/* @__PURE__ */ jsx(Label, { htmlFor: "email", children: "Your Email" }),
|
|
34
|
+
/* @__PURE__ */ jsx(
|
|
35
|
+
Input,
|
|
36
|
+
{
|
|
37
|
+
id: "email",
|
|
38
|
+
type: "email",
|
|
39
|
+
...register("email"),
|
|
40
|
+
onChange: () => clearErrors("email")
|
|
41
|
+
}
|
|
42
|
+
),
|
|
43
|
+
/* @__PURE__ */ jsx(FormWarningText, { text: errors.email?.message?.toString() }),
|
|
44
|
+
/* @__PURE__ */ jsx(
|
|
45
|
+
Button,
|
|
46
|
+
{
|
|
47
|
+
type: "submit",
|
|
48
|
+
style: { marginTop: "1.5rem" },
|
|
49
|
+
children: "Send Email"
|
|
50
|
+
}
|
|
51
|
+
)
|
|
52
|
+
]
|
|
53
|
+
}
|
|
54
|
+
);
|
|
52
55
|
}
|
|
53
56
|
export {
|
|
54
57
|
ForgotPassword as default
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/components/forgot-password.tsx"],"sourcesContent":["'use client';\n\nimport {
|
|
1
|
+
{"version":3,"sources":["../../../src/components/forgot-password.tsx"],"sourcesContent":["'use client';\n\nimport { useForm } from \"react-hook-form\";\nimport { yupResolver } from \"@hookform/resolvers/yup\";\nimport * as yup from \"yup\";\nimport FormWarningText from \"./form-warning\";\nimport { useStackApp } from \"..\";\nimport { Button, Input, Label } from \"../components-core\";\nimport { runAsynchronously } from \"@stackframe/stack-shared/dist/utils/promises\";\n\nconst schema = yup.object().shape({\n email: yup.string().email('Please enter a valid email').required('Please enter your email')\n});\n\nexport default function ForgotPassword({ onSent }: { onSent?: () => void }) {\n const { register, handleSubmit, formState: { errors }, clearErrors } = useForm({\n resolver: yupResolver(schema)\n });\n const stackApp = useStackApp();\n\n const onSubmit = async (data: yup.InferType<typeof schema>) => {\n const { email } = data;\n await stackApp.sendForgotPasswordEmail(email);\n onSent?.();\n };\n\n return (\n <form\n style={{ display: 'flex', flexDirection: 'column', alignItems: 'stretch' }} \n onSubmit={e => runAsynchronously(handleSubmit(onSubmit)(e))}\n noValidate\n >\n <Label htmlFor=\"email\">Your Email</Label>\n <Input\n id=\"email\"\n type=\"email\"\n {...register('email')}\n onChange={() => clearErrors('email')}\n />\n <FormWarningText text={errors.email?.message?.toString()} />\n\n <Button\n type=\"submit\"\n style={{ marginTop: '1.5rem' }}\n >\n Send Email\n </Button>\n </form>\n );\n}\n"],"mappings":";;;AAEA,SAAS,eAAe;AACxB,SAAS,mBAAmB;AAC5B,YAAY,SAAS;AACrB,OAAO,qBAAqB;AAC5B,SAAS,mBAAmB;AAC5B,SAAS,QAAQ,OAAO,aAAa;AACrC,SAAS,yBAAyB;AAmB9B,SAKE,KALF;AAjBJ,IAAM,SAAa,WAAO,EAAE,MAAM;AAAA,EAChC,OAAW,WAAO,EAAE,MAAM,4BAA4B,EAAE,SAAS,yBAAyB;AAC5F,CAAC;AAEc,SAAR,eAAgC,EAAE,OAAO,GAA4B;AAC1E,QAAM,EAAE,UAAU,cAAc,WAAW,EAAE,OAAO,GAAG,YAAY,IAAI,QAAQ;AAAA,IAC7E,UAAU,YAAY,MAAM;AAAA,EAC9B,CAAC;AACD,QAAM,WAAW,YAAY;AAE7B,QAAM,WAAW,OAAO,SAAuC;AAC7D,UAAM,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