@wordrhyme/shadcn-auth 1.0.61 → 2.0.3
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/README.md +154 -1
- package/dist/components/AuthCard.cjs +45 -0
- package/dist/components/AuthCard.d.cts +30 -0
- package/dist/components/AuthCard.d.ts +30 -0
- package/dist/components/AuthCard.js +42 -0
- package/dist/components/AuthForms.cjs +115 -0
- package/dist/components/AuthForms.d.cts +95 -0
- package/dist/components/AuthForms.d.ts +95 -0
- package/dist/components/AuthForms.js +112 -0
- package/dist/components/CompleteProfileForm.cjs +38 -0
- package/dist/components/CompleteProfileForm.d.cts +32 -0
- package/dist/components/CompleteProfileForm.d.ts +32 -0
- package/dist/components/CompleteProfileForm.js +36 -0
- package/dist/components/EmailOtpForm.cjs +181 -0
- package/dist/components/EmailOtpForm.d.cts +56 -0
- package/dist/components/EmailOtpForm.d.ts +56 -0
- package/dist/components/EmailOtpForm.js +176 -0
- package/dist/components/LegalNotice.cjs +37 -0
- package/dist/components/LegalNotice.d.cts +26 -0
- package/dist/components/LegalNotice.d.ts +26 -0
- package/dist/components/LegalNotice.js +35 -0
- package/dist/components/MagicLinkForm.cjs +119 -0
- package/dist/components/MagicLinkForm.d.cts +46 -0
- package/dist/components/MagicLinkForm.d.ts +46 -0
- package/dist/components/MagicLinkForm.js +115 -0
- package/dist/components/ProviderSignInButtons.cjs +65 -0
- package/dist/components/ProviderSignInButtons.d.cts +41 -0
- package/dist/components/ProviderSignInButtons.d.ts +41 -0
- package/dist/components/ProviderSignInButtons.js +62 -0
- package/dist/components/ResetPasswordForm.cjs +89 -0
- package/dist/components/ResetPasswordForm.d.cts +20 -0
- package/dist/components/ResetPasswordForm.d.ts +20 -0
- package/dist/components/ResetPasswordForm.js +85 -0
- package/dist/components/SignInForm.cjs +97 -0
- package/dist/components/SignInForm.d.cts +41 -0
- package/dist/components/SignInForm.d.ts +41 -0
- package/dist/components/SignInForm.js +93 -0
- package/dist/components/SignUpForm.cjs +123 -0
- package/dist/components/SignUpForm.d.cts +40 -0
- package/dist/components/SignUpForm.d.ts +40 -0
- package/dist/components/SignUpForm.js +119 -0
- package/dist/components/auth-pending/AuthButton.cjs +37 -0
- package/dist/components/auth-pending/AuthButton.d.cts +36 -0
- package/dist/components/auth-pending/AuthButton.d.ts +36 -0
- package/dist/components/auth-pending/AuthButton.js +34 -0
- package/dist/components/auth-pending/AuthPendingProvider.cjs +19 -0
- package/dist/components/auth-pending/AuthPendingProvider.d.cts +17 -0
- package/dist/components/auth-pending/AuthPendingProvider.d.ts +17 -0
- package/dist/components/auth-pending/AuthPendingProvider.js +17 -0
- package/dist/components/auth-pending/auth-pending-context.cjs +57 -0
- package/dist/components/auth-pending/auth-pending-context.d.cts +39 -0
- package/dist/components/auth-pending/auth-pending-context.d.ts +39 -0
- package/dist/components/auth-pending/auth-pending-context.js +52 -0
- package/dist/components/auth-pending/index.d.cts +3 -0
- package/dist/components/auth-pending/index.d.ts +3 -0
- package/dist/components/forms/AuthField.cjs +43 -0
- package/dist/components/forms/AuthField.d.cts +26 -0
- package/dist/components/forms/AuthField.d.ts +26 -0
- package/dist/components/forms/AuthField.js +40 -0
- package/dist/components/forms/CompleteProfileFields.cjs +63 -0
- package/dist/components/forms/CompleteProfileFields.d.cts +18 -0
- package/dist/components/forms/CompleteProfileFields.d.ts +18 -0
- package/dist/components/forms/CompleteProfileFields.js +60 -0
- package/dist/components/forms/EmailOtpCodeForm.cjs +78 -0
- package/dist/components/forms/EmailOtpCodeForm.d.cts +18 -0
- package/dist/components/forms/EmailOtpCodeForm.d.ts +18 -0
- package/dist/components/forms/EmailOtpCodeForm.js +75 -0
- package/dist/components/forms/EmailRequestForm.cjs +82 -0
- package/dist/components/forms/EmailRequestForm.d.cts +38 -0
- package/dist/components/forms/EmailRequestForm.d.ts +38 -0
- package/dist/components/forms/EmailRequestForm.js +79 -0
- package/dist/components/forms/SignInCredentialsForm.cjs +79 -0
- package/dist/components/forms/SignInCredentialsForm.d.cts +18 -0
- package/dist/components/forms/SignInCredentialsForm.d.ts +18 -0
- package/dist/components/forms/SignInCredentialsForm.js +76 -0
- package/dist/components/forms/SignUpCredentialsForm.cjs +130 -0
- package/dist/components/forms/SignUpCredentialsForm.d.cts +24 -0
- package/dist/components/forms/SignUpCredentialsForm.d.ts +24 -0
- package/dist/components/forms/SignUpCredentialsForm.js +126 -0
- package/dist/components/index.d.cts +25 -0
- package/dist/components/index.d.ts +25 -0
- package/dist/components/provider-icon/ProviderIcon.cjs +82 -0
- package/dist/components/provider-icon/ProviderIcon.d.cts +21 -0
- package/dist/components/provider-icon/ProviderIcon.d.ts +21 -0
- package/dist/components/provider-icon/ProviderIcon.js +79 -0
- package/dist/components/sign-in-methods/SignInMethodRow.cjs +55 -0
- package/dist/components/sign-in-methods/SignInMethodRow.d.cts +31 -0
- package/dist/components/sign-in-methods/SignInMethodRow.d.ts +31 -0
- package/dist/components/sign-in-methods/SignInMethodRow.js +50 -0
- package/dist/components/sign-in-methods/SignInMethods.cjs +45 -0
- package/dist/components/sign-in-methods/SignInMethods.d.cts +26 -0
- package/dist/components/sign-in-methods/SignInMethods.d.ts +26 -0
- package/dist/components/sign-in-methods/SignInMethods.js +43 -0
- package/dist/components/sign-in-methods/SignInMethodsList.cjs +69 -0
- package/dist/components/sign-in-methods/SignInMethodsList.d.cts +47 -0
- package/dist/components/sign-in-methods/SignInMethodsList.d.ts +47 -0
- package/dist/components/sign-in-methods/SignInMethodsList.js +65 -0
- package/dist/components/sign-in-methods/sign-in-methods-copy.cjs +13 -0
- package/dist/components/sign-in-methods/sign-in-methods-copy.d.cts +11 -0
- package/dist/components/sign-in-methods/sign-in-methods-copy.d.ts +11 -0
- package/dist/components/sign-in-methods/sign-in-methods-copy.js +12 -0
- package/dist/constants/auth-providers.cjs +33 -0
- package/dist/constants/auth-providers.d.cts +14 -0
- package/dist/constants/auth-providers.d.ts +14 -0
- package/dist/constants/auth-providers.js +31 -0
- package/dist/constants/validation.cjs +21 -0
- package/dist/constants/validation.d.cts +17 -0
- package/dist/constants/validation.d.ts +17 -0
- package/dist/constants/validation.js +18 -0
- package/dist/hooks/use-pending-action.cjs +37 -0
- package/dist/hooks/use-pending-action.d.cts +26 -0
- package/dist/hooks/use-pending-action.d.ts +26 -0
- package/dist/hooks/use-pending-action.js +35 -0
- package/dist/hooks/use-reset-on-page-restore.cjs +35 -0
- package/dist/hooks/use-reset-on-page-restore.d.cts +15 -0
- package/dist/hooks/use-reset-on-page-restore.d.ts +15 -0
- package/dist/hooks/use-reset-on-page-restore.js +33 -0
- package/dist/index.cjs +67 -7
- package/dist/index.d.cts +34 -6
- package/dist/index.d.ts +34 -6
- package/dist/index.js +33 -6
- package/dist/utils/build-sign-in-method-rows.cjs +25 -0
- package/dist/utils/build-sign-in-method-rows.d.cts +26 -0
- package/dist/utils/build-sign-in-method-rows.d.ts +26 -0
- package/dist/utils/build-sign-in-method-rows.js +24 -0
- package/dist/utils/until-navigation.cjs +22 -0
- package/dist/utils/until-navigation.d.cts +18 -0
- package/dist/utils/until-navigation.d.ts +18 -0
- package/dist/utils/until-navigation.js +21 -0
- package/dist/utils/validate-email.cjs +22 -0
- package/dist/utils/validate-email.d.cts +14 -0
- package/dist/utils/validate-email.d.ts +14 -0
- package/dist/utils/validate-email.js +21 -0
- package/dist/utils/validate-password.cjs +16 -0
- package/dist/utils/validate-password.d.cts +9 -0
- package/dist/utils/validate-password.d.ts +9 -0
- package/dist/utils/validate-password.js +16 -0
- package/package.json +15 -8
- package/dist/AuthForms.cjs +0 -47
- package/dist/AuthForms.d.cts +0 -23
- package/dist/AuthForms.d.ts +0 -23
- package/dist/AuthForms.js +0 -44
- package/dist/GoogleSignIn.cjs +0 -46
- package/dist/GoogleSignIn.d.cts +0 -10
- package/dist/GoogleSignIn.d.ts +0 -10
- package/dist/GoogleSignIn.js +0 -42
- package/dist/ResetPasswordForm.cjs +0 -106
- package/dist/ResetPasswordForm.d.cts +0 -17
- package/dist/ResetPasswordForm.d.ts +0 -17
- package/dist/ResetPasswordForm.js +0 -100
- package/dist/SignInForm.cjs +0 -164
- package/dist/SignInForm.d.cts +0 -21
- package/dist/SignInForm.d.ts +0 -21
- package/dist/SignInForm.js +0 -159
- package/dist/SignUpForm.cjs +0 -154
- package/dist/SignUpForm.d.cts +0 -19
- package/dist/SignUpForm.d.ts +0 -19
- package/dist/SignUpForm.js +0 -149
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { SignInMethodsListProps } from "./SignInMethodsList.js";
|
|
2
|
+
import * as react_jsx_runtime14 from "react/jsx-runtime";
|
|
3
|
+
|
|
4
|
+
//#region src/components/sign-in-methods/SignInMethods.d.ts
|
|
5
|
+
interface SignInMethodsProps extends SignInMethodsListProps {}
|
|
6
|
+
/**
|
|
7
|
+
* The account's sign-in methods: what is connected, and what can be added.
|
|
8
|
+
*
|
|
9
|
+
* Presentational by design — the host owns fetching, the connect action, and
|
|
10
|
+
* the error/success copy, exactly as the login screen owns them for
|
|
11
|
+
* `AuthForms`. Adding GitHub or LinkedIn later is one more entry in
|
|
12
|
+
* `linkableProviders`; nothing in here is provider-specific.
|
|
13
|
+
*
|
|
14
|
+
* This is the composed default, heading included, for a host with no section
|
|
15
|
+
* card of its own. A host that has one renders {@link SignInMethodsList} under
|
|
16
|
+
* its own heading and takes the wording from {@link SIGN_IN_METHODS_COPY}.
|
|
17
|
+
*/
|
|
18
|
+
declare function SignInMethods({
|
|
19
|
+
className,
|
|
20
|
+
...props
|
|
21
|
+
}: SignInMethodsProps): react_jsx_runtime14.JSX.Element;
|
|
22
|
+
declare namespace SignInMethods {
|
|
23
|
+
var displayName: string;
|
|
24
|
+
}
|
|
25
|
+
//#endregion
|
|
26
|
+
export { SignInMethods, SignInMethodsProps };
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
import { SIGN_IN_METHODS_COPY } from "./sign-in-methods-copy.js";
|
|
5
|
+
import { SignInMethodsList } from "./SignInMethodsList.js";
|
|
6
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
7
|
+
|
|
8
|
+
//#region src/components/sign-in-methods/SignInMethods.tsx
|
|
9
|
+
/**
|
|
10
|
+
* The account's sign-in methods: what is connected, and what can be added.
|
|
11
|
+
*
|
|
12
|
+
* Presentational by design — the host owns fetching, the connect action, and
|
|
13
|
+
* the error/success copy, exactly as the login screen owns them for
|
|
14
|
+
* `AuthForms`. Adding GitHub or LinkedIn later is one more entry in
|
|
15
|
+
* `linkableProviders`; nothing in here is provider-specific.
|
|
16
|
+
*
|
|
17
|
+
* This is the composed default, heading included, for a host with no section
|
|
18
|
+
* card of its own. A host that has one renders {@link SignInMethodsList} under
|
|
19
|
+
* its own heading and takes the wording from {@link SIGN_IN_METHODS_COPY}.
|
|
20
|
+
*/
|
|
21
|
+
function SignInMethods({ className,...props }) {
|
|
22
|
+
return /* @__PURE__ */ jsxs("div", {
|
|
23
|
+
className,
|
|
24
|
+
children: [
|
|
25
|
+
/* @__PURE__ */ jsx("h3", {
|
|
26
|
+
className: "font-medium",
|
|
27
|
+
children: SIGN_IN_METHODS_COPY.title
|
|
28
|
+
}),
|
|
29
|
+
/* @__PURE__ */ jsx("p", {
|
|
30
|
+
className: "text-muted-foreground mt-1 text-sm",
|
|
31
|
+
children: SIGN_IN_METHODS_COPY.description
|
|
32
|
+
}),
|
|
33
|
+
/* @__PURE__ */ jsx(SignInMethodsList, {
|
|
34
|
+
...props,
|
|
35
|
+
className: "mt-4"
|
|
36
|
+
})
|
|
37
|
+
]
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
SignInMethods.displayName = "SignInMethods";
|
|
41
|
+
|
|
42
|
+
//#endregion
|
|
43
|
+
export { SignInMethods };
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
const require_rolldown_runtime = require('../../_virtual/rolldown_runtime.cjs');
|
|
5
|
+
const require_SignInMethodRow = require('./SignInMethodRow.cjs');
|
|
6
|
+
const require_build_sign_in_method_rows = require('../../utils/build-sign-in-method-rows.cjs');
|
|
7
|
+
let react_jsx_runtime = require("react/jsx-runtime");
|
|
8
|
+
react_jsx_runtime = require_rolldown_runtime.__toESM(react_jsx_runtime);
|
|
9
|
+
let __wordrhyme_shadcn = require("@wordrhyme/shadcn");
|
|
10
|
+
__wordrhyme_shadcn = require_rolldown_runtime.__toESM(__wordrhyme_shadcn);
|
|
11
|
+
let lucide_react = require("lucide-react");
|
|
12
|
+
lucide_react = require_rolldown_runtime.__toESM(lucide_react);
|
|
13
|
+
|
|
14
|
+
//#region src/components/sign-in-methods/SignInMethodsList.tsx
|
|
15
|
+
/** Shared empty default, so the prop identity is stable across renders. */
|
|
16
|
+
const NO_PROVIDERS = [];
|
|
17
|
+
/**
|
|
18
|
+
* The body of the sign-in methods section: the how-to, the outcome messages,
|
|
19
|
+
* and the list itself — everything but the heading.
|
|
20
|
+
*
|
|
21
|
+
* Split out from {@link SignInMethods} so a host can supply its own section
|
|
22
|
+
* heading, alongside {@link SIGN_IN_METHODS_COPY} when it wants this one.
|
|
23
|
+
*/
|
|
24
|
+
function SignInMethodsList({ identities, linkableProviders = NO_PROVIDERS, isLoading = false, pendingProvider = null, error = null, notice = null, onConnect, className }) {
|
|
25
|
+
const rows = require_build_sign_in_method_rows.buildSignInMethodRows(identities, linkableProviders);
|
|
26
|
+
const hasConnectableProvider = rows.some((row) => !row.isConnected);
|
|
27
|
+
const hasError = error != null && error.trim() !== "";
|
|
28
|
+
const hasNotice = !hasError && notice != null && notice.trim() !== "";
|
|
29
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
30
|
+
className,
|
|
31
|
+
children: [
|
|
32
|
+
hasConnectableProvider && /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
33
|
+
className: "text-muted-foreground text-sm",
|
|
34
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", { children: "To add another sign-in method:" }), /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("ol", {
|
|
35
|
+
"aria-label": "How to add a sign-in method",
|
|
36
|
+
className: "mt-2 list-decimal space-y-1 pl-5",
|
|
37
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("li", { children: "Choose Connect next to the provider you want to add." }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("li", { children: "Sign in to that provider and approve the connection." })]
|
|
38
|
+
})]
|
|
39
|
+
}),
|
|
40
|
+
hasError && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(__wordrhyme_shadcn.Alert, {
|
|
41
|
+
variant: "destructive",
|
|
42
|
+
className: "mt-4",
|
|
43
|
+
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(__wordrhyme_shadcn.AlertDescription, { children: error })
|
|
44
|
+
}),
|
|
45
|
+
hasNotice && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(__wordrhyme_shadcn.Alert, {
|
|
46
|
+
className: "mt-4",
|
|
47
|
+
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(__wordrhyme_shadcn.AlertDescription, { children: notice })
|
|
48
|
+
}),
|
|
49
|
+
isLoading ? /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("p", {
|
|
50
|
+
className: "text-muted-foreground mt-4 flex items-center gap-2 text-sm",
|
|
51
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(lucide_react.Loader2, { className: "h-4 w-4 animate-spin" }), "Loading sign-in methods..."]
|
|
52
|
+
}) : /* @__PURE__ */ (0, react_jsx_runtime.jsx)("ul", {
|
|
53
|
+
className: "divide-border mt-2 divide-y",
|
|
54
|
+
children: rows.map((row) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_SignInMethodRow.SignInMethodRow, {
|
|
55
|
+
provider: row.provider,
|
|
56
|
+
email: row.email,
|
|
57
|
+
isConnected: row.isConnected,
|
|
58
|
+
isPending: pendingProvider === row.provider,
|
|
59
|
+
isDisabled: pendingProvider != null,
|
|
60
|
+
onConnect
|
|
61
|
+
}, row.provider))
|
|
62
|
+
})
|
|
63
|
+
]
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
SignInMethodsList.displayName = "SignInMethodsList";
|
|
67
|
+
|
|
68
|
+
//#endregion
|
|
69
|
+
exports.SignInMethodsList = SignInMethodsList;
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { SignInMethodIdentity } from "../../utils/build-sign-in-method-rows.cjs";
|
|
2
|
+
import * as react_jsx_runtime17 from "react/jsx-runtime";
|
|
3
|
+
|
|
4
|
+
//#region src/components/sign-in-methods/SignInMethodsList.d.ts
|
|
5
|
+
interface SignInMethodsListProps {
|
|
6
|
+
/** Methods already attached to the account, password identity included. */
|
|
7
|
+
identities: readonly SignInMethodIdentity[];
|
|
8
|
+
/**
|
|
9
|
+
* Providers this host offers to connect, in display order. A provider that is
|
|
10
|
+
* already linked is filtered out, so passing every configured provider is
|
|
11
|
+
* safe. Empty by default — a host that offers none shows the list read-only.
|
|
12
|
+
*/
|
|
13
|
+
linkableProviders?: readonly string[];
|
|
14
|
+
/** True while {@link identities} is still being fetched. */
|
|
15
|
+
isLoading?: boolean;
|
|
16
|
+
/** Provider whose connect flow is in flight, if any. */
|
|
17
|
+
pendingProvider?: string | null;
|
|
18
|
+
/** Failure copy, from the connect action or from the callback's return leg. */
|
|
19
|
+
error?: string | null;
|
|
20
|
+
/** Success copy, shown after a provider has been connected. */
|
|
21
|
+
notice?: string | null;
|
|
22
|
+
/** Starts connecting `provider`. */
|
|
23
|
+
onConnect: (provider: string) => void;
|
|
24
|
+
className?: string;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* The body of the sign-in methods section: the how-to, the outcome messages,
|
|
28
|
+
* and the list itself — everything but the heading.
|
|
29
|
+
*
|
|
30
|
+
* Split out from {@link SignInMethods} so a host can supply its own section
|
|
31
|
+
* heading, alongside {@link SIGN_IN_METHODS_COPY} when it wants this one.
|
|
32
|
+
*/
|
|
33
|
+
declare function SignInMethodsList({
|
|
34
|
+
identities,
|
|
35
|
+
linkableProviders,
|
|
36
|
+
isLoading,
|
|
37
|
+
pendingProvider,
|
|
38
|
+
error,
|
|
39
|
+
notice,
|
|
40
|
+
onConnect,
|
|
41
|
+
className
|
|
42
|
+
}: SignInMethodsListProps): react_jsx_runtime17.JSX.Element;
|
|
43
|
+
declare namespace SignInMethodsList {
|
|
44
|
+
var displayName: string;
|
|
45
|
+
}
|
|
46
|
+
//#endregion
|
|
47
|
+
export { SignInMethodsList, SignInMethodsListProps };
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { SignInMethodIdentity } from "../../utils/build-sign-in-method-rows.js";
|
|
2
|
+
import * as react_jsx_runtime16 from "react/jsx-runtime";
|
|
3
|
+
|
|
4
|
+
//#region src/components/sign-in-methods/SignInMethodsList.d.ts
|
|
5
|
+
interface SignInMethodsListProps {
|
|
6
|
+
/** Methods already attached to the account, password identity included. */
|
|
7
|
+
identities: readonly SignInMethodIdentity[];
|
|
8
|
+
/**
|
|
9
|
+
* Providers this host offers to connect, in display order. A provider that is
|
|
10
|
+
* already linked is filtered out, so passing every configured provider is
|
|
11
|
+
* safe. Empty by default — a host that offers none shows the list read-only.
|
|
12
|
+
*/
|
|
13
|
+
linkableProviders?: readonly string[];
|
|
14
|
+
/** True while {@link identities} is still being fetched. */
|
|
15
|
+
isLoading?: boolean;
|
|
16
|
+
/** Provider whose connect flow is in flight, if any. */
|
|
17
|
+
pendingProvider?: string | null;
|
|
18
|
+
/** Failure copy, from the connect action or from the callback's return leg. */
|
|
19
|
+
error?: string | null;
|
|
20
|
+
/** Success copy, shown after a provider has been connected. */
|
|
21
|
+
notice?: string | null;
|
|
22
|
+
/** Starts connecting `provider`. */
|
|
23
|
+
onConnect: (provider: string) => void;
|
|
24
|
+
className?: string;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* The body of the sign-in methods section: the how-to, the outcome messages,
|
|
28
|
+
* and the list itself — everything but the heading.
|
|
29
|
+
*
|
|
30
|
+
* Split out from {@link SignInMethods} so a host can supply its own section
|
|
31
|
+
* heading, alongside {@link SIGN_IN_METHODS_COPY} when it wants this one.
|
|
32
|
+
*/
|
|
33
|
+
declare function SignInMethodsList({
|
|
34
|
+
identities,
|
|
35
|
+
linkableProviders,
|
|
36
|
+
isLoading,
|
|
37
|
+
pendingProvider,
|
|
38
|
+
error,
|
|
39
|
+
notice,
|
|
40
|
+
onConnect,
|
|
41
|
+
className
|
|
42
|
+
}: SignInMethodsListProps): react_jsx_runtime16.JSX.Element;
|
|
43
|
+
declare namespace SignInMethodsList {
|
|
44
|
+
var displayName: string;
|
|
45
|
+
}
|
|
46
|
+
//#endregion
|
|
47
|
+
export { SignInMethodsList, SignInMethodsListProps };
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
import { SignInMethodRow } from "./SignInMethodRow.js";
|
|
5
|
+
import { buildSignInMethodRows } from "../../utils/build-sign-in-method-rows.js";
|
|
6
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
7
|
+
import { Alert, AlertDescription } from "@wordrhyme/shadcn";
|
|
8
|
+
import { Loader2 } from "lucide-react";
|
|
9
|
+
|
|
10
|
+
//#region src/components/sign-in-methods/SignInMethodsList.tsx
|
|
11
|
+
/** Shared empty default, so the prop identity is stable across renders. */
|
|
12
|
+
const NO_PROVIDERS = [];
|
|
13
|
+
/**
|
|
14
|
+
* The body of the sign-in methods section: the how-to, the outcome messages,
|
|
15
|
+
* and the list itself — everything but the heading.
|
|
16
|
+
*
|
|
17
|
+
* Split out from {@link SignInMethods} so a host can supply its own section
|
|
18
|
+
* heading, alongside {@link SIGN_IN_METHODS_COPY} when it wants this one.
|
|
19
|
+
*/
|
|
20
|
+
function SignInMethodsList({ identities, linkableProviders = NO_PROVIDERS, isLoading = false, pendingProvider = null, error = null, notice = null, onConnect, className }) {
|
|
21
|
+
const rows = buildSignInMethodRows(identities, linkableProviders);
|
|
22
|
+
const hasConnectableProvider = rows.some((row) => !row.isConnected);
|
|
23
|
+
const hasError = error != null && error.trim() !== "";
|
|
24
|
+
const hasNotice = !hasError && notice != null && notice.trim() !== "";
|
|
25
|
+
return /* @__PURE__ */ jsxs("div", {
|
|
26
|
+
className,
|
|
27
|
+
children: [
|
|
28
|
+
hasConnectableProvider && /* @__PURE__ */ jsxs("div", {
|
|
29
|
+
className: "text-muted-foreground text-sm",
|
|
30
|
+
children: [/* @__PURE__ */ jsx("p", { children: "To add another sign-in method:" }), /* @__PURE__ */ jsxs("ol", {
|
|
31
|
+
"aria-label": "How to add a sign-in method",
|
|
32
|
+
className: "mt-2 list-decimal space-y-1 pl-5",
|
|
33
|
+
children: [/* @__PURE__ */ jsx("li", { children: "Choose Connect next to the provider you want to add." }), /* @__PURE__ */ jsx("li", { children: "Sign in to that provider and approve the connection." })]
|
|
34
|
+
})]
|
|
35
|
+
}),
|
|
36
|
+
hasError && /* @__PURE__ */ jsx(Alert, {
|
|
37
|
+
variant: "destructive",
|
|
38
|
+
className: "mt-4",
|
|
39
|
+
children: /* @__PURE__ */ jsx(AlertDescription, { children: error })
|
|
40
|
+
}),
|
|
41
|
+
hasNotice && /* @__PURE__ */ jsx(Alert, {
|
|
42
|
+
className: "mt-4",
|
|
43
|
+
children: /* @__PURE__ */ jsx(AlertDescription, { children: notice })
|
|
44
|
+
}),
|
|
45
|
+
isLoading ? /* @__PURE__ */ jsxs("p", {
|
|
46
|
+
className: "text-muted-foreground mt-4 flex items-center gap-2 text-sm",
|
|
47
|
+
children: [/* @__PURE__ */ jsx(Loader2, { className: "h-4 w-4 animate-spin" }), "Loading sign-in methods..."]
|
|
48
|
+
}) : /* @__PURE__ */ jsx("ul", {
|
|
49
|
+
className: "divide-border mt-2 divide-y",
|
|
50
|
+
children: rows.map((row) => /* @__PURE__ */ jsx(SignInMethodRow, {
|
|
51
|
+
provider: row.provider,
|
|
52
|
+
email: row.email,
|
|
53
|
+
isConnected: row.isConnected,
|
|
54
|
+
isPending: pendingProvider === row.provider,
|
|
55
|
+
isDisabled: pendingProvider != null,
|
|
56
|
+
onConnect
|
|
57
|
+
}, row.provider))
|
|
58
|
+
})
|
|
59
|
+
]
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
SignInMethodsList.displayName = "SignInMethodsList";
|
|
63
|
+
|
|
64
|
+
//#endregion
|
|
65
|
+
export { SignInMethodsList };
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
|
|
2
|
+
//#region src/components/sign-in-methods/sign-in-methods-copy.ts
|
|
3
|
+
/**
|
|
4
|
+
* The section's own wording, exported so a host can put it in whatever card or
|
|
5
|
+
* heading its layout uses instead of having this package render one.
|
|
6
|
+
*/
|
|
7
|
+
const SIGN_IN_METHODS_COPY = {
|
|
8
|
+
title: "Sign-in methods",
|
|
9
|
+
description: "The ways you can sign in to this account. Connecting another one keeps the same account and all of its data — it only adds a new way in."
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
//#endregion
|
|
13
|
+
exports.SIGN_IN_METHODS_COPY = SIGN_IN_METHODS_COPY;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
//#region src/components/sign-in-methods/sign-in-methods-copy.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* The section's own wording, exported so a host can put it in whatever card or
|
|
4
|
+
* heading its layout uses instead of having this package render one.
|
|
5
|
+
*/
|
|
6
|
+
declare const SIGN_IN_METHODS_COPY: {
|
|
7
|
+
readonly title: "Sign-in methods";
|
|
8
|
+
readonly description: "The ways you can sign in to this account. Connecting another one keeps the same account and all of its data — it only adds a new way in.";
|
|
9
|
+
};
|
|
10
|
+
//#endregion
|
|
11
|
+
export { SIGN_IN_METHODS_COPY };
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
//#region src/components/sign-in-methods/sign-in-methods-copy.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* The section's own wording, exported so a host can put it in whatever card or
|
|
4
|
+
* heading its layout uses instead of having this package render one.
|
|
5
|
+
*/
|
|
6
|
+
declare const SIGN_IN_METHODS_COPY: {
|
|
7
|
+
readonly title: "Sign-in methods";
|
|
8
|
+
readonly description: "The ways you can sign in to this account. Connecting another one keeps the same account and all of its data — it only adds a new way in.";
|
|
9
|
+
};
|
|
10
|
+
//#endregion
|
|
11
|
+
export { SIGN_IN_METHODS_COPY };
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
//#region src/components/sign-in-methods/sign-in-methods-copy.ts
|
|
2
|
+
/**
|
|
3
|
+
* The section's own wording, exported so a host can put it in whatever card or
|
|
4
|
+
* heading its layout uses instead of having this package render one.
|
|
5
|
+
*/
|
|
6
|
+
const SIGN_IN_METHODS_COPY = {
|
|
7
|
+
title: "Sign-in methods",
|
|
8
|
+
description: "The ways you can sign in to this account. Connecting another one keeps the same account and all of its data — it only adds a new way in."
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
//#endregion
|
|
12
|
+
export { SIGN_IN_METHODS_COPY };
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
|
|
2
|
+
//#region src/constants/auth-providers.ts
|
|
3
|
+
/**
|
|
4
|
+
* How each Supabase provider key is presented.
|
|
5
|
+
*
|
|
6
|
+
* Keyed by the raw provider string rather than a closed union on purpose: a
|
|
7
|
+
* provider enabled on the Supabase side should render sensibly here without a
|
|
8
|
+
* code change, and {@link describeAuthProvider} falls back to a readable label
|
|
9
|
+
* for anything not listed.
|
|
10
|
+
*/
|
|
11
|
+
const AUTH_PROVIDER_LABELS = {
|
|
12
|
+
email: "Email and password",
|
|
13
|
+
phone: "Phone",
|
|
14
|
+
google: "Google",
|
|
15
|
+
github: "GitHub",
|
|
16
|
+
gitlab: "GitLab",
|
|
17
|
+
linkedin_oidc: "LinkedIn",
|
|
18
|
+
azure: "Microsoft",
|
|
19
|
+
apple: "Apple",
|
|
20
|
+
facebook: "Facebook"
|
|
21
|
+
};
|
|
22
|
+
/** Turns `linkedin_oidc` into `Linkedin Oidc` — last resort, not a lookup. */
|
|
23
|
+
function humanizeProvider(provider) {
|
|
24
|
+
return provider.split(/[_-]/u).filter((part) => part.length > 0).map((part) => part.charAt(0).toUpperCase() + part.slice(1)).join(" ");
|
|
25
|
+
}
|
|
26
|
+
/** The label to show for a provider key. */
|
|
27
|
+
function describeAuthProvider(provider) {
|
|
28
|
+
return AUTH_PROVIDER_LABELS[provider] ?? humanizeProvider(provider);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
//#endregion
|
|
32
|
+
exports.AUTH_PROVIDER_LABELS = AUTH_PROVIDER_LABELS;
|
|
33
|
+
exports.describeAuthProvider = describeAuthProvider;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
//#region src/constants/auth-providers.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* How each Supabase provider key is presented.
|
|
4
|
+
*
|
|
5
|
+
* Keyed by the raw provider string rather than a closed union on purpose: a
|
|
6
|
+
* provider enabled on the Supabase side should render sensibly here without a
|
|
7
|
+
* code change, and {@link describeAuthProvider} falls back to a readable label
|
|
8
|
+
* for anything not listed.
|
|
9
|
+
*/
|
|
10
|
+
declare const AUTH_PROVIDER_LABELS: Record<string, string>;
|
|
11
|
+
/** The label to show for a provider key. */
|
|
12
|
+
declare function describeAuthProvider(provider: string): string;
|
|
13
|
+
//#endregion
|
|
14
|
+
export { AUTH_PROVIDER_LABELS, describeAuthProvider };
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
//#region src/constants/auth-providers.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* How each Supabase provider key is presented.
|
|
4
|
+
*
|
|
5
|
+
* Keyed by the raw provider string rather than a closed union on purpose: a
|
|
6
|
+
* provider enabled on the Supabase side should render sensibly here without a
|
|
7
|
+
* code change, and {@link describeAuthProvider} falls back to a readable label
|
|
8
|
+
* for anything not listed.
|
|
9
|
+
*/
|
|
10
|
+
declare const AUTH_PROVIDER_LABELS: Record<string, string>;
|
|
11
|
+
/** The label to show for a provider key. */
|
|
12
|
+
declare function describeAuthProvider(provider: string): string;
|
|
13
|
+
//#endregion
|
|
14
|
+
export { AUTH_PROVIDER_LABELS, describeAuthProvider };
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
//#region src/constants/auth-providers.ts
|
|
2
|
+
/**
|
|
3
|
+
* How each Supabase provider key is presented.
|
|
4
|
+
*
|
|
5
|
+
* Keyed by the raw provider string rather than a closed union on purpose: a
|
|
6
|
+
* provider enabled on the Supabase side should render sensibly here without a
|
|
7
|
+
* code change, and {@link describeAuthProvider} falls back to a readable label
|
|
8
|
+
* for anything not listed.
|
|
9
|
+
*/
|
|
10
|
+
const AUTH_PROVIDER_LABELS = {
|
|
11
|
+
email: "Email and password",
|
|
12
|
+
phone: "Phone",
|
|
13
|
+
google: "Google",
|
|
14
|
+
github: "GitHub",
|
|
15
|
+
gitlab: "GitLab",
|
|
16
|
+
linkedin_oidc: "LinkedIn",
|
|
17
|
+
azure: "Microsoft",
|
|
18
|
+
apple: "Apple",
|
|
19
|
+
facebook: "Facebook"
|
|
20
|
+
};
|
|
21
|
+
/** Turns `linkedin_oidc` into `Linkedin Oidc` — last resort, not a lookup. */
|
|
22
|
+
function humanizeProvider(provider) {
|
|
23
|
+
return provider.split(/[_-]/u).filter((part) => part.length > 0).map((part) => part.charAt(0).toUpperCase() + part.slice(1)).join(" ");
|
|
24
|
+
}
|
|
25
|
+
/** The label to show for a provider key. */
|
|
26
|
+
function describeAuthProvider(provider) {
|
|
27
|
+
return AUTH_PROVIDER_LABELS[provider] ?? humanizeProvider(provider);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
//#endregion
|
|
31
|
+
export { AUTH_PROVIDER_LABELS, describeAuthProvider };
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
|
|
2
|
+
//#region src/constants/validation.ts
|
|
3
|
+
/**
|
|
4
|
+
* Client-side form limits.
|
|
5
|
+
*
|
|
6
|
+
* These mirror rules the server enforces independently — the forms check them
|
|
7
|
+
* so the user gets an answer without a round trip, never so the server can skip
|
|
8
|
+
* checking. Server-owned limits are passed to components by the host so client
|
|
9
|
+
* feedback stays aligned with the server's rules.
|
|
10
|
+
*/
|
|
11
|
+
/** Matches Supabase's own `minimum_password_length` default. */
|
|
12
|
+
const MIN_PASSWORD_LENGTH = 6;
|
|
13
|
+
/** Age stated by the default Terms copy on the sign-up form. */
|
|
14
|
+
const DEFAULT_MINIMUM_AGE = 16;
|
|
15
|
+
/** Digits Supabase's `otp_length` is configured to emit. */
|
|
16
|
+
const OTP_LENGTH = 6;
|
|
17
|
+
|
|
18
|
+
//#endregion
|
|
19
|
+
exports.DEFAULT_MINIMUM_AGE = DEFAULT_MINIMUM_AGE;
|
|
20
|
+
exports.MIN_PASSWORD_LENGTH = MIN_PASSWORD_LENGTH;
|
|
21
|
+
exports.OTP_LENGTH = OTP_LENGTH;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
//#region src/constants/validation.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* Client-side form limits.
|
|
4
|
+
*
|
|
5
|
+
* These mirror rules the server enforces independently — the forms check them
|
|
6
|
+
* so the user gets an answer without a round trip, never so the server can skip
|
|
7
|
+
* checking. Server-owned limits are passed to components by the host so client
|
|
8
|
+
* feedback stays aligned with the server's rules.
|
|
9
|
+
*/
|
|
10
|
+
/** Matches Supabase's own `minimum_password_length` default. */
|
|
11
|
+
declare const MIN_PASSWORD_LENGTH = 6;
|
|
12
|
+
/** Age stated by the default Terms copy on the sign-up form. */
|
|
13
|
+
declare const DEFAULT_MINIMUM_AGE = 16;
|
|
14
|
+
/** Digits Supabase's `otp_length` is configured to emit. */
|
|
15
|
+
declare const OTP_LENGTH = 6;
|
|
16
|
+
//#endregion
|
|
17
|
+
export { DEFAULT_MINIMUM_AGE, MIN_PASSWORD_LENGTH, OTP_LENGTH };
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
//#region src/constants/validation.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* Client-side form limits.
|
|
4
|
+
*
|
|
5
|
+
* These mirror rules the server enforces independently — the forms check them
|
|
6
|
+
* so the user gets an answer without a round trip, never so the server can skip
|
|
7
|
+
* checking. Server-owned limits are passed to components by the host so client
|
|
8
|
+
* feedback stays aligned with the server's rules.
|
|
9
|
+
*/
|
|
10
|
+
/** Matches Supabase's own `minimum_password_length` default. */
|
|
11
|
+
declare const MIN_PASSWORD_LENGTH = 6;
|
|
12
|
+
/** Age stated by the default Terms copy on the sign-up form. */
|
|
13
|
+
declare const DEFAULT_MINIMUM_AGE = 16;
|
|
14
|
+
/** Digits Supabase's `otp_length` is configured to emit. */
|
|
15
|
+
declare const OTP_LENGTH = 6;
|
|
16
|
+
//#endregion
|
|
17
|
+
export { DEFAULT_MINIMUM_AGE, MIN_PASSWORD_LENGTH, OTP_LENGTH };
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
//#region src/constants/validation.ts
|
|
2
|
+
/**
|
|
3
|
+
* Client-side form limits.
|
|
4
|
+
*
|
|
5
|
+
* These mirror rules the server enforces independently — the forms check them
|
|
6
|
+
* so the user gets an answer without a round trip, never so the server can skip
|
|
7
|
+
* checking. Server-owned limits are passed to components by the host so client
|
|
8
|
+
* feedback stays aligned with the server's rules.
|
|
9
|
+
*/
|
|
10
|
+
/** Matches Supabase's own `minimum_password_length` default. */
|
|
11
|
+
const MIN_PASSWORD_LENGTH = 6;
|
|
12
|
+
/** Age stated by the default Terms copy on the sign-up form. */
|
|
13
|
+
const DEFAULT_MINIMUM_AGE = 16;
|
|
14
|
+
/** Digits Supabase's `otp_length` is configured to emit. */
|
|
15
|
+
const OTP_LENGTH = 6;
|
|
16
|
+
|
|
17
|
+
//#endregion
|
|
18
|
+
export { DEFAULT_MINIMUM_AGE, MIN_PASSWORD_LENGTH, OTP_LENGTH };
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
const require_rolldown_runtime = require('../_virtual/rolldown_runtime.cjs');
|
|
5
|
+
let react = require("react");
|
|
6
|
+
react = require_rolldown_runtime.__toESM(react);
|
|
7
|
+
|
|
8
|
+
//#region src/hooks/use-pending-action.ts
|
|
9
|
+
/**
|
|
10
|
+
* Tracks *which* of several buttons started the work in flight.
|
|
11
|
+
*
|
|
12
|
+
* A single `isLoading` flag can only say that something is happening, not what
|
|
13
|
+
* — so a row of buttons sharing one flag spins every one of them when a user
|
|
14
|
+
* clicks a single button. Keeping the key of the action that actually started
|
|
15
|
+
* lets the button the user pressed show the spinner while its neighbours only
|
|
16
|
+
* go disabled.
|
|
17
|
+
*
|
|
18
|
+
* An action that navigates away (an OAuth redirect) never settles, so the
|
|
19
|
+
* spinner deliberately keeps running until the page is gone.
|
|
20
|
+
*/
|
|
21
|
+
function usePendingAction() {
|
|
22
|
+
const [pendingKey, setPendingKey] = (0, react.useState)(null);
|
|
23
|
+
const reset = (0, react.useCallback)(() => setPendingKey(null), []);
|
|
24
|
+
const run = (0, react.useCallback)((key, action) => {
|
|
25
|
+
setPendingKey(key);
|
|
26
|
+
action().catch(console.error).finally(() => setPendingKey(null));
|
|
27
|
+
}, []);
|
|
28
|
+
return {
|
|
29
|
+
pendingKey,
|
|
30
|
+
isPending: pendingKey != null,
|
|
31
|
+
run,
|
|
32
|
+
reset
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
//#endregion
|
|
37
|
+
exports.usePendingAction = usePendingAction;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
//#region src/hooks/use-pending-action.d.ts
|
|
2
|
+
interface PendingAction<TKey extends string> {
|
|
3
|
+
/** Key of the action currently in flight, or `null` when none is. */
|
|
4
|
+
pendingKey: TKey | null;
|
|
5
|
+
/** Whether an action is in flight — the cue for disabling the others. */
|
|
6
|
+
isPending: boolean;
|
|
7
|
+
/** Starts `action` and marks `key` as the one running until it settles. */
|
|
8
|
+
run: (key: TKey, action: () => Promise<void>) => void;
|
|
9
|
+
/** Clears the pending key without waiting for its action to settle. */
|
|
10
|
+
reset: () => void;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Tracks *which* of several buttons started the work in flight.
|
|
14
|
+
*
|
|
15
|
+
* A single `isLoading` flag can only say that something is happening, not what
|
|
16
|
+
* — so a row of buttons sharing one flag spins every one of them when a user
|
|
17
|
+
* clicks a single button. Keeping the key of the action that actually started
|
|
18
|
+
* lets the button the user pressed show the spinner while its neighbours only
|
|
19
|
+
* go disabled.
|
|
20
|
+
*
|
|
21
|
+
* An action that navigates away (an OAuth redirect) never settles, so the
|
|
22
|
+
* spinner deliberately keeps running until the page is gone.
|
|
23
|
+
*/
|
|
24
|
+
declare function usePendingAction<TKey extends string = string>(): PendingAction<TKey>;
|
|
25
|
+
//#endregion
|
|
26
|
+
export { PendingAction, usePendingAction };
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
//#region src/hooks/use-pending-action.d.ts
|
|
2
|
+
interface PendingAction<TKey extends string> {
|
|
3
|
+
/** Key of the action currently in flight, or `null` when none is. */
|
|
4
|
+
pendingKey: TKey | null;
|
|
5
|
+
/** Whether an action is in flight — the cue for disabling the others. */
|
|
6
|
+
isPending: boolean;
|
|
7
|
+
/** Starts `action` and marks `key` as the one running until it settles. */
|
|
8
|
+
run: (key: TKey, action: () => Promise<void>) => void;
|
|
9
|
+
/** Clears the pending key without waiting for its action to settle. */
|
|
10
|
+
reset: () => void;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Tracks *which* of several buttons started the work in flight.
|
|
14
|
+
*
|
|
15
|
+
* A single `isLoading` flag can only say that something is happening, not what
|
|
16
|
+
* — so a row of buttons sharing one flag spins every one of them when a user
|
|
17
|
+
* clicks a single button. Keeping the key of the action that actually started
|
|
18
|
+
* lets the button the user pressed show the spinner while its neighbours only
|
|
19
|
+
* go disabled.
|
|
20
|
+
*
|
|
21
|
+
* An action that navigates away (an OAuth redirect) never settles, so the
|
|
22
|
+
* spinner deliberately keeps running until the page is gone.
|
|
23
|
+
*/
|
|
24
|
+
declare function usePendingAction<TKey extends string = string>(): PendingAction<TKey>;
|
|
25
|
+
//#endregion
|
|
26
|
+
export { PendingAction, usePendingAction };
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
import { useCallback, useState } from "react";
|
|
5
|
+
|
|
6
|
+
//#region src/hooks/use-pending-action.ts
|
|
7
|
+
/**
|
|
8
|
+
* Tracks *which* of several buttons started the work in flight.
|
|
9
|
+
*
|
|
10
|
+
* A single `isLoading` flag can only say that something is happening, not what
|
|
11
|
+
* — so a row of buttons sharing one flag spins every one of them when a user
|
|
12
|
+
* clicks a single button. Keeping the key of the action that actually started
|
|
13
|
+
* lets the button the user pressed show the spinner while its neighbours only
|
|
14
|
+
* go disabled.
|
|
15
|
+
*
|
|
16
|
+
* An action that navigates away (an OAuth redirect) never settles, so the
|
|
17
|
+
* spinner deliberately keeps running until the page is gone.
|
|
18
|
+
*/
|
|
19
|
+
function usePendingAction() {
|
|
20
|
+
const [pendingKey, setPendingKey] = useState(null);
|
|
21
|
+
const reset = useCallback(() => setPendingKey(null), []);
|
|
22
|
+
const run = useCallback((key, action) => {
|
|
23
|
+
setPendingKey(key);
|
|
24
|
+
action().catch(console.error).finally(() => setPendingKey(null));
|
|
25
|
+
}, []);
|
|
26
|
+
return {
|
|
27
|
+
pendingKey,
|
|
28
|
+
isPending: pendingKey != null,
|
|
29
|
+
run,
|
|
30
|
+
reset
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
//#endregion
|
|
35
|
+
export { usePendingAction };
|