@kirill.konshin/mui 0.0.6 → 0.0.7
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.
|
@@ -16,7 +16,8 @@ export type AdminSignInPageProps = Omit<SignInPageProps, "signIn"> & {
|
|
|
16
16
|
/**
|
|
17
17
|
* Toolpad `SignInPage` preconfigured for the password-only login of `@kirill.konshin/auth`: single
|
|
18
18
|
* credentials provider, no email/rememberMe fields, errors surfaced through the form. On success
|
|
19
|
-
* `loginAction` redirects (handled by Next.js)
|
|
19
|
+
* `loginAction` redirects (handled by Next.js) and the form stays busy until the next page replaces it,
|
|
20
|
+
* on failure its message is shown.
|
|
20
21
|
*/
|
|
21
22
|
export declare const AdminSignInPage: FC<AdminSignInPageProps>;
|
|
22
23
|
//#endregion
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"signInPage.d.ts","names":[],"sources":["../../src/admin/signInPage.tsx"],"mappings":";;;;
|
|
1
|
+
{"version":3,"file":"signInPage.d.ts","names":[],"sources":["../../src/admin/signInPage.tsx"],"mappings":";;;;KAUK,kBAAkB,sBAAsB;YAEjC,uBAAuB,KAAK;;EAEpC,aAAa;;EAEb;;EAEA;;EAEA;;;;;;;;qBA+BS,iBAAiB,GAAG"}
|
package/dist/admin/signInPage.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { memo, useCallback } from "react";
|
|
3
3
|
import { jsx } from "react/jsx-runtime";
|
|
4
|
+
import { unstable_rethrow } from "next/navigation";
|
|
4
5
|
import { formLabelClasses } from "@mui/material/FormLabel";
|
|
5
6
|
import { SignInPage } from "@toolpad/core/SignInPage";
|
|
6
7
|
//#region src/admin/signInPage.tsx
|
|
@@ -10,17 +11,32 @@ const DEFAULT_PROVIDERS = [{
|
|
|
10
11
|
name: "password"
|
|
11
12
|
}];
|
|
12
13
|
const NOT_CONFIGURED_SUBTITLE = "Set ADMIN_PASSWORD and a SESSION_SECRET of at least 32 characters, then restart.";
|
|
14
|
+
/** Whether Next.js handles `error` itself, like the redirect it rejects a redirecting Server Action call with. */
|
|
15
|
+
const isNextNavigation = (error) => {
|
|
16
|
+
try {
|
|
17
|
+
unstable_rethrow(error);
|
|
18
|
+
return false;
|
|
19
|
+
} catch {
|
|
20
|
+
return true;
|
|
21
|
+
}
|
|
22
|
+
};
|
|
13
23
|
/**
|
|
14
24
|
* Toolpad `SignInPage` preconfigured for the password-only login of `@kirill.konshin/auth`: single
|
|
15
25
|
* credentials provider, no email/rememberMe fields, errors surfaced through the form. On success
|
|
16
|
-
* `loginAction` redirects (handled by Next.js)
|
|
26
|
+
* `loginAction` redirects (handled by Next.js) and the form stays busy until the next page replaces it,
|
|
27
|
+
* on failure its message is shown.
|
|
17
28
|
*/
|
|
18
29
|
const AdminSignInPage = memo(function AdminSignInPage({ loginAction, isConfigured = true, notConfiguredSubtitle = NOT_CONFIGURED_SUBTITLE, providers = DEFAULT_PROVIDERS, state, localeText, slots, slotProps, ...props }) {
|
|
19
30
|
const signIn = useCallback(async (_provider, formData) => {
|
|
20
31
|
if (!(formData instanceof FormData)) return { error: "Password is required" };
|
|
21
32
|
if (state) formData.set(STATE_PARAM, state);
|
|
22
|
-
|
|
23
|
-
|
|
33
|
+
try {
|
|
34
|
+
const error = await loginAction(null, formData);
|
|
35
|
+
return error ? { error } : {};
|
|
36
|
+
} catch (error) {
|
|
37
|
+
if (isNextNavigation(error)) return new Promise(() => {});
|
|
38
|
+
throw error;
|
|
39
|
+
}
|
|
24
40
|
}, [loginAction, state]);
|
|
25
41
|
return /* @__PURE__ */ jsx(SignInPage, {
|
|
26
42
|
signIn,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"signInPage.js","names":[],"sources":["../../src/admin/signInPage.tsx"],"sourcesContent":["'use client';\n\nimport React, { type ComponentProps, type FC, memo, useCallback } from 'react';\n\nimport { type PasswordAuth } from '@kirill.konshin/auth';\nimport type { STATE_PARAM as StateParam } from '@kirill.konshin/auth/client';\nimport { formLabelClasses } from '@mui/material/FormLabel';\nimport { SignInPage } from '@toolpad/core/SignInPage';\n\ntype SignInPageProps = ComponentProps<typeof SignInPage>;\n\nexport type AdminSignInPageProps = Omit<SignInPageProps, 'signIn'> & {\n /** `auth.loginFormAction` from `@kirill.konshin/auth`, re-exported from a `'use server'` file */\n loginAction: PasswordAuth['loginFormAction'];\n /** Pass `auth.isConfigured()` to render setup instructions instead of the form, default true */\n isConfigured?: boolean;\n /** Subtitle shown when not configured */\n notConfiguredSubtitle?: string;\n /** Sanitized return URL (`auth.getState(await searchParams)`), threaded into the login form */\n state?: string;\n};\n\n/*\n * Inlined, NOT imported at runtime: `@kirill.konshin/auth` is an OPTIONAL peer, so importing\n * `@kirill.konshin/auth/client` here would make the whole `/admin` entry unresolvable in apps that\n * only use `AdminAppProvider`/`AdminDashboardLayout` (the barrel re-exports this module). The\n * annotation is a compile-time guard: it stops resolving the day auth renames the param.\n */\nconst STATE_PARAM: typeof StateParam = 'state';\n\nconst DEFAULT_PROVIDERS: SignInPageProps['providers'] = [{ id: 'credentials', name: 'password' }];\n\nconst NOT_CONFIGURED_SUBTITLE = 'Set ADMIN_PASSWORD and a SESSION_SECRET of at least 32 characters, then restart.';\n\n/**\n * Toolpad `SignInPage` preconfigured for the password-only login of `@kirill.konshin/auth`: single\n * credentials provider, no email/rememberMe fields, errors surfaced through the form. On success\n * `loginAction` redirects (handled by Next.js)
|
|
1
|
+
{"version":3,"file":"signInPage.js","names":[],"sources":["../../src/admin/signInPage.tsx"],"sourcesContent":["'use client';\n\nimport React, { type ComponentProps, type FC, memo, useCallback } from 'react';\n\nimport { type PasswordAuth } from '@kirill.konshin/auth';\nimport type { STATE_PARAM as StateParam } from '@kirill.konshin/auth/client';\nimport { formLabelClasses } from '@mui/material/FormLabel';\nimport { SignInPage } from '@toolpad/core/SignInPage';\nimport { unstable_rethrow } from 'next/navigation';\n\ntype SignInPageProps = ComponentProps<typeof SignInPage>;\n\nexport type AdminSignInPageProps = Omit<SignInPageProps, 'signIn'> & {\n /** `auth.loginFormAction` from `@kirill.konshin/auth`, re-exported from a `'use server'` file */\n loginAction: PasswordAuth['loginFormAction'];\n /** Pass `auth.isConfigured()` to render setup instructions instead of the form, default true */\n isConfigured?: boolean;\n /** Subtitle shown when not configured */\n notConfiguredSubtitle?: string;\n /** Sanitized return URL (`auth.getState(await searchParams)`), threaded into the login form */\n state?: string;\n};\n\n/*\n * Inlined, NOT imported at runtime: `@kirill.konshin/auth` is an OPTIONAL peer, so importing\n * `@kirill.konshin/auth/client` here would make the whole `/admin` entry unresolvable in apps that\n * only use `AdminAppProvider`/`AdminDashboardLayout` (the barrel re-exports this module). The\n * annotation is a compile-time guard: it stops resolving the day auth renames the param.\n */\nconst STATE_PARAM: typeof StateParam = 'state';\n\nconst DEFAULT_PROVIDERS: SignInPageProps['providers'] = [{ id: 'credentials', name: 'password' }];\n\nconst NOT_CONFIGURED_SUBTITLE = 'Set ADMIN_PASSWORD and a SESSION_SECRET of at least 32 characters, then restart.';\n\n/** Whether Next.js handles `error` itself, like the redirect it rejects a redirecting Server Action call with. */\nconst isNextNavigation = (error: unknown): boolean => {\n try {\n unstable_rethrow(error);\n return false;\n } catch {\n return true;\n }\n};\n\n/**\n * Toolpad `SignInPage` preconfigured for the password-only login of `@kirill.konshin/auth`: single\n * credentials provider, no email/rememberMe fields, errors surfaced through the form. On success\n * `loginAction` redirects (handled by Next.js) and the form stays busy until the next page replaces it,\n * on failure its message is shown.\n */\nexport const AdminSignInPage: FC<AdminSignInPageProps> = memo(function AdminSignInPage({\n loginAction,\n isConfigured = true,\n notConfiguredSubtitle = NOT_CONFIGURED_SUBTITLE,\n providers = DEFAULT_PROVIDERS,\n state,\n localeText,\n slots,\n slotProps,\n ...props\n}) {\n const signIn = useCallback<NonNullable<SignInPageProps['signIn']>>(\n async (_provider, formData) => {\n if (!(formData instanceof FormData)) return { error: 'Password is required' };\n // thread the return URL through the form only — never store it in the session,\n // multiple tabs logging in concurrently would clash\n if (state) formData.set(STATE_PARAM, state);\n try {\n const error = await loginAction(null, formData);\n return error ? { error } : {};\n } catch (error) {\n // Next.js rejects the call with its redirect error while it navigates; Toolpad's submit\n // handler has no catch, so stay pending instead of leaving an unhandled rejection\n if (isNextNavigation(error)) return new Promise<never>(() => {});\n throw error;\n }\n },\n [loginAction, state],\n );\n\n return (\n <SignInPage\n signIn={signIn}\n providers={isConfigured ? providers : []}\n localeText={\n isConfigured\n ? localeText\n : {\n signInTitle: 'Authentication needs configuration',\n signInSubtitle: notConfiguredSubtitle,\n ...localeText,\n }\n }\n slots={{\n emailField: () => null,\n rememberMe: () => null,\n subtitle: () => null,\n ...slots,\n }}\n slotProps={{\n ...slotProps,\n // FIXME https://github.com/mui/toolpad/issues/4572 — still relevant in 0.16:\n // browser validation popups fight the server-side errors (noValidate is settable\n // declaratively through the form slot) and the password label renders misaligned;\n // re-check on Toolpad upgrades\n form: { noValidate: true, ...slotProps?.form },\n passwordField: {\n autoFocus: true,\n sx: { [`& .${formLabelClasses.root}`]: { top: '-2px' } },\n ...slotProps?.passwordField,\n },\n submitButton: { variant: 'contained', ...slotProps?.submitButton },\n }}\n {...props}\n />\n );\n});\n"],"mappings":";;;;;;;AA6BA,MAAM,cAAiC;AAEvC,MAAM,oBAAkD,CAAC;CAAE,IAAI;CAAe,MAAM;AAAW,CAAC;AAEhG,MAAM,0BAA0B;;AAGhC,MAAM,oBAAoB,UAA4B;CAClD,IAAI;EACA,iBAAiB,KAAK;EACtB,OAAO;CACX,QAAQ;EACJ,OAAO;CACX;AACJ;;;;;;;AAQA,MAAa,kBAA4C,KAAK,SAAS,gBAAgB,EACnF,aACA,eAAe,MACf,wBAAwB,yBACxB,YAAY,mBACZ,OACA,YACA,OACA,WACA,GAAG,SACJ;CACC,MAAM,SAAS,YACX,OAAO,WAAW,aAAa;EAC3B,IAAI,EAAE,oBAAoB,WAAW,OAAO,EAAE,OAAO,uBAAuB;EAG5E,IAAI,OAAO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