@supatype/react-auth 0.9.0 → 0.9.2

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.
@@ -1,4 +1,4 @@
1
1
 
2
- > @supatype/react-auth@0.9.0 build /home/runner/work/supatype/supatype/packages/react-auth
2
+ > @supatype/react-auth@0.9.2 build /home/runner/work/supatype/supatype/packages/react-auth
3
3
  > tsc
4
4
 
@@ -1,20 +1,22 @@
1
1
 
2
- > @supatype/react-auth@0.9.0 test /home/runner/work/supatype/supatype/packages/react-auth
2
+ > @supatype/react-auth@0.9.2 test /home/runner/work/supatype/supatype/packages/react-auth
3
3
  > vitest run --maxWorkers=50% --passWithNoTests
4
4
 
5
5
 
6
6
   RUN  v4.0.18 /home/runner/work/supatype/supatype/packages/react-auth
7
7
 
8
- ✓ tests/oauth-button.test.tsx (4 tests) 110ms
9
- ✓ tests/email-link-forms.test.tsx (11 tests) 556ms
10
- ✓ asks /recover to email a reset link that returns to redirectTo, then says to check the email  302ms
11
- ✓ tests/login-form.test.tsx (3 tests) 259ms
12
- ✓ tests/password-recovery.test.tsx (2 tests) 185ms
13
- ✓ tests/signup-confirmation.test.tsx (1 test) 192ms
14
- ✓ tests/auth-ui.test.tsx (6 tests) 30ms
8
+ ✓ tests/sso-form.test.tsx (6 tests) 392ms
9
+ ✓ starts SSO for the domain of the email typed and sends the browser to the identity provider  314ms
10
+ ✓ tests/email-link-forms.test.tsx (11 tests) 596ms
11
+ ✓ tests/oauth-button.test.tsx (4 tests) 88ms
12
+ ✓ tests/setup-fault.test.tsx (2 tests) 203ms
13
+ ✓ tests/password-recovery.test.tsx (3 tests) 199ms
14
+ ✓ tests/login-form.test.tsx (3 tests) 211ms
15
+ ✓ tests/signup-confirmation.test.tsx (1 test) 217ms
16
+ ✓ tests/auth-ui.test.tsx (6 tests) 60ms
15
17
 
16
-  Test Files  6 passed (6)
17
-  Tests  27 passed (27)
18
-  Start at  22:36:29
19
-  Duration  8.33s (transform 5.63s, setup 0ms, import 10.77s, tests 1.33s, environment 1ms)
18
+  Test Files  8 passed (8)
19
+  Tests  36 passed (36)
20
+  Start at  12:02:03
21
+  Duration  9.00s (transform 3.04s, setup 0ms, import 9.61s, tests 1.97s, environment 34ms)
20
22
 
@@ -1,4 +1,4 @@
1
1
 
2
- > @supatype/react-auth@0.9.0 typecheck /home/runner/work/supatype/supatype/packages/react-auth
2
+ > @supatype/react-auth@0.9.2 typecheck /home/runner/work/supatype/supatype/packages/react-auth
3
3
  > tsc --project tests/tsconfig.json --noEmit
4
4
 
package/CHANGELOG.md ADDED
@@ -0,0 +1,23 @@
1
+ # Changelog
2
+
3
+ ## Unreleased
4
+
5
+ ### Features
6
+
7
+ * **sso:** `SSOForm` signs the user in through their organisation's SAML identity provider. It
8
+ takes a work email (or a bare domain), calls `signInWithSSO` with its domain and sends the
9
+ browser to the identity provider. Like the other forms it disables itself while the request
10
+ runs, shows the server's refusal (no provider for the domain, a disabled one) and calls
11
+ `onError`. A sign-in the server refused on the way back is shown above the field and passed to
12
+ `onError` too, through the same hook `OAuthButton` uses for its provider. It takes
13
+ `redirectTo`, `onSuccess`, `onError`, `className`, `labels` and `classNames`.
14
+
15
+ ### Bug Fixes
16
+
17
+ * **forms:** a form over a client with no API address or anon key shows the client's
18
+ `MissingClientValuesError` as its error, calls `onError` with it, and stops loading. The client
19
+ throws that error from the request rather than answering with it, and the forms passed it on as
20
+ an unhandled rejection, so every sign-in and sign-up form stayed on its spinner.
21
+ * **forms:** the error a form shows for a client with no API address or anon key is the
22
+ `MissingClientValuesError` itself, a `SupatypeError` like every other request's error now is,
23
+ rather than a plain `{ message }`.
@@ -1 +1 @@
1
- {"version":3,"file":"OAuthButton.d.ts","sourceRoot":"","sources":["../src/OAuthButton.tsx"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,KAAK,EAAE,EAA+B,KAAK,SAAS,EAAE,MAAM,OAAO,CAAA;AAG1E,MAAM,WAAW,gBAAgB;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O,GAAG,SAAS,CAAA;IAC3B,6BAA6B;IAC7B,QAAQ,CAAC,EAAE,OAAO,GAAG,SAAS,CAAA;CAC/B;AAuFD;;;;;GAKG;AACH,wBAAgB,WAAW,CAAC,KAAK,EAAE,gBAAgB,GAAG,KAAK,CAAC,YAAY,CAyBvE"}
@@ -12,8 +12,9 @@ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
12
12
  * <OAuthButton provider="apple" className="dark-btn">Sign in with Apple</OAuthButton>
13
13
  * ```
14
14
  */
15
- import { useEffect, useRef, useState } from "react";
15
+ import { useState } from "react";
16
16
  import { useAuth } from "@supatype/react";
17
+ import { useRedirectError } from "./useRedirectError.js";
17
18
  /** Names whose capitalisation is not just a capital first letter. */
18
19
  const PROVIDER_NAMES = {
19
20
  github: "GitHub",
@@ -61,20 +62,6 @@ function defaultStyle(busy) {
61
62
  lineHeight: 1,
62
63
  };
63
64
  }
64
- /**
65
- * Report a refusal the auth server sent back in the URL, when this button's provider started it.
66
- *
67
- * Through a ref so an inline `onError` does not report the same refusal on every render.
68
- */
69
- function useRedirectError(provider, onError) {
70
- const { error } = useAuth();
71
- const onErrorRef = useRef(onError);
72
- onErrorRef.current = onError;
73
- useEffect(() => {
74
- if (error !== null && error.provider === provider)
75
- onErrorRef.current?.(error);
76
- }, [error, provider]);
77
- }
78
65
  /**
79
66
  * The button's click: ask for the provider's URL and go there, or report why not.
80
67
  *
@@ -1 +1 @@
1
- {"version":3,"file":"OAuthButton.js","sourceRoot":"","sources":["../src/OAuthButton.tsx"],"names":[],"mappings":";AAAA;;;;;;;;;;;;GAYG;AAEH,OAAc,EAAE,SAAS,EAAE,MAAM,EAAE,QAAQ,EAAkB,MAAM,OAAO,CAAA;AAC1E,OAAO,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAA;AAmBzC,qEAAqE;AACrE,MAAM,cAAc,GAA2B;IAC7C,MAAM,EAAE,QAAQ;IAChB,MAAM,EAAE,QAAQ;IAChB,QAAQ,EAAE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,CAAC,CAAA;IACtD,MAAM,IAAI,GAAG,QAAQ,KAAK,IAAI,IAAI,OAAO,CAAA;IAEzC,OAAO,CACL,kBACE,IAAI,EAAC,QAAQ,EACb,SAAS,EAAE,SAAS,EACpB,KAAK,EAAE,SAAS,KAAK,SAAS,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,YAAY,CAAC,IAAI,CAAC,EAC/D,OAAO,EAAE,GAAG,EAAE,GAAG,KAAK,KAAK,EAAE,CAAA,CAAC,CAAC,EAC/B,QAAQ,EAAE,IAAI,aAEb,OAAO,KAAK,SAAS,IAAI,CACxB,8BACc,MAAM,EAClB,uBAAuB,EAAE,EAAE,MAAM,EAAE,OAAO,EAAE,EAC5C,KAAK,EAAE,EAAE,OAAO,EAAE,aAAa,EAAE,UAAU,EAAE,QAAQ,EAAE,GACvD,CACH,EACA,QAAQ,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC,iBAAiB,YAAY,GAAG,CAAC,CAAC,CAAC,gBAAgB,YAAY,EAAE,CAAC,IACnF,CACV,CAAA;AACH,CAAC"}
@@ -0,0 +1,39 @@
1
+ import React from "react";
2
+ import { SupatypeError } from "@supatype/client";
3
+ import type { AuthFormClassNames } from "./classNames.js";
4
+ export interface SSOFormLabels {
5
+ title?: string | undefined;
6
+ email?: string | undefined;
7
+ submit?: string | undefined;
8
+ /** Shown in place of the form while the browser goes to the identity provider. */
9
+ successMessage?: string | undefined;
10
+ }
11
+ export interface SSOFormProps {
12
+ /** Where the browser lands once the identity provider has signed the user in. */
13
+ redirectTo?: string | undefined;
14
+ /** Called with the identity provider's URL as the browser is sent there. */
15
+ onSuccess?: ((url: string) => void) | undefined;
16
+ /** Called with the error returned by the auth service, or the form's own refusal of the address. */
17
+ onError?: ((error: SupatypeError) => void) | undefined;
18
+ /** CSS class applied to the outermost <form> element. */
19
+ className?: string | undefined;
20
+ /** Override display labels. */
21
+ labels?: SSOFormLabels | undefined;
22
+ /** Class names for the elements inside the form, so an app can style them with its own classes. */
23
+ classNames?: AuthFormClassNames | undefined;
24
+ }
25
+ /**
26
+ * Signs the user in through their organisation's SAML identity provider, found by the domain of
27
+ * the email they type (`signInWithSSO`, `POST /sso`). Must be rendered inside a `<SupatypeProvider>`.
28
+ *
29
+ * The browser goes to the identity provider and comes back signed in on `redirectTo` (honoured on
30
+ * the site URL's host or the auth server's redirect allow list, else the site URL). A sign-in the
31
+ * server refused on the way back is shown above the field and passed to `onError`.
32
+ *
33
+ * @example
34
+ * ```tsx
35
+ * <SSOForm redirectTo={window.location.origin} />
36
+ * ```
37
+ */
38
+ export declare function SSOForm(props: SSOFormProps): React.ReactElement;
39
+ //# sourceMappingURL=SSOForm.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"SSOForm.d.ts","sourceRoot":"","sources":["../src/SSOForm.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAmB,MAAM,OAAO,CAAA;AACvC,OAAO,EAAgB,aAAa,EAAwD,MAAM,kBAAkB,CAAA;AAEpH,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,iBAAiB,CAAA;AAIzD,MAAM,WAAW,aAAa;IAC5B,KAAK,CAAC,EAAE,MAAM,GAAG,SAAS,CAAA;IAC1B,KAAK,CAAC,EAAE,MAAM,GAAG,SAAS,CAAA;IAC1B,MAAM,CAAC,EAAE,MAAM,GAAG,SAAS,CAAA;IAC3B,kFAAkF;IAClF,cAAc,CAAC,EAAE,MAAM,GAAG,SAAS,CAAA;CACpC;AAED,MAAM,WAAW,YAAY;IAC3B,iFAAiF;IACjF,UAAU,CAAC,EAAE,MAAM,GAAG,SAAS,CAAA;IAC/B,4EAA4E;IAC5E,SAAS,CAAC,EAAE,CAAC,CAAC,GAAG,EAAE,MAAM,KAAK,IAAI,CAAC,GAAG,SAAS,CAAA;IAC/C,oGAAoG;IACpG,OAAO,CAAC,EAAE,CAAC,CAAC,KAAK,EAAE,aAAa,KAAK,IAAI,CAAC,GAAG,SAAS,CAAA;IACtD,yDAAyD;IACzD,SAAS,CAAC,EAAE,MAAM,GAAG,SAAS,CAAA;IAC9B,+BAA+B;IAC/B,MAAM,CAAC,EAAE,aAAa,GAAG,SAAS,CAAA;IAClC,mGAAmG;IACnG,UAAU,CAAC,EAAE,kBAAkB,GAAG,SAAS,CAAA;CAC5C;AAqBD;;;;;;;;;;;;GAYG;AACH,wBAAgB,OAAO,CAAC,KAAK,EAAE,YAAY,GAAG,KAAK,CAAC,YAAY,CA+B/D"}
@@ -0,0 +1,47 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { useState } from "react";
3
+ import { SSO_PROVIDER, SupatypeError, ssoDomain } from "@supatype/client";
4
+ import { useSupatype } from "@supatype/react";
5
+ import { FormField, FormShell, FormMessage, useAuthSubmit, withDefaults } from "./formParts.js";
6
+ import { useRedirectError } from "./useRedirectError.js";
7
+ const DEFAULT_LABELS = {
8
+ title: "Sign in with SSO",
9
+ email: "Work email",
10
+ submit: "Continue with SSO",
11
+ successMessage: "Redirecting to your identity provider…",
12
+ };
13
+ const NO_DOMAIN = "Enter your work email address.";
14
+ /** Start SSO for the address typed, refusing one with no domain before the server is asked. */
15
+ function startSSO(auth, email, redirectTo) {
16
+ const domain = ssoDomain(email);
17
+ if (domain === null) {
18
+ const error = new SupatypeError({ message: NO_DOMAIN, code: "validation_failed" });
19
+ return Promise.resolve({ data: { url: "" }, error });
20
+ }
21
+ return auth.signInWithSSO({ domain, ...(redirectTo !== undefined && { options: { redirectTo } }) });
22
+ }
23
+ /**
24
+ * Signs the user in through their organisation's SAML identity provider, found by the domain of
25
+ * the email they type (`signInWithSSO`, `POST /sso`). Must be rendered inside a `<SupatypeProvider>`.
26
+ *
27
+ * The browser goes to the identity provider and comes back signed in on `redirectTo` (honoured on
28
+ * the site URL's host or the auth server's redirect allow list, else the site URL). A sign-in the
29
+ * server refused on the way back is shown above the field and passed to `onError`.
30
+ *
31
+ * @example
32
+ * ```tsx
33
+ * <SSOForm redirectTo={window.location.origin} />
34
+ * ```
35
+ */
36
+ export function SSOForm(props) {
37
+ const { auth } = useSupatype();
38
+ const { redirectTo, onSuccess, onError, className, classNames } = props;
39
+ const l = withDefaults(DEFAULT_LABELS, props.labels);
40
+ const [email, setEmail] = useState("");
41
+ const redirectError = useRedirectError(SSO_PROVIDER, onError);
42
+ const request = useAuthSubmit(() => startSSO(auth, email, redirectTo), { onDone: (data) => onSuccess?.(data.url), onError });
43
+ if (request.done)
44
+ return _jsx(FormMessage, { text: l.successMessage, classNames: classNames });
45
+ return (_jsx(FormShell, { request: request, text: { title: l.title, submit: l.submit, busy: "Redirecting…" }, className: className, classNames: classNames, errorMessage: request.errorMessage ?? redirectError?.message, children: _jsx(FormField, { id: "st-sso-email", label: l.email, classNames: classNames, type: "email", autoComplete: "email", required: true, value: email, onChange: (e) => setEmail(e.target.value), disabled: request.loading }) }));
46
+ }
47
+ //# sourceMappingURL=SSOForm.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"SSOForm.js","sourceRoot":"","sources":["../src/SSOForm.tsx"],"names":[],"mappings":";AAAA,OAAc,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAA;AACvC,OAAO,EAAE,YAAY,EAAE,aAAa,EAAE,SAAS,EAA6C,MAAM,kBAAkB,CAAA;AACpH,OAAO,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAA;AAE7C,OAAO,EAAE,SAAS,EAAE,SAAS,EAAE,WAAW,EAAE,aAAa,EAAE,YAAY,EAAe,MAAM,gBAAgB,CAAA;AAC5G,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAA;AAyBxD,MAAM,cAAc,GAA0B;IAC5C,KAAK,EAAE,kBAAkB;IACzB,KAAK,EAAE,YAAY;IACnB,MAAM,EAAE,mBAAmB;IAC3B,cAAc,EAAE,wCAAwC;CACzD,CAAA;AAED,MAAM,SAAS,GAAG,gCAAgC,CAAA;AAElD,+FAA+F;AAC/F,SAAS,QAAQ,CAAC,IAAgB,EAAE,KAAa,EAAE,UAA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AAS,CAAA;CACvD;AAyBD;;;;;;GAMG;AACH,wBAAgB,aAAa,CAAC,CAAC,EAC7B,IAAI,EAAE,MAAM,OAAO,CAAC;IAAE,IAAI,EAAE,CAAC,CAAC;IAAC,KAAK,EAAE,aAAa,GAAG,IAAI,CAAA;CAAE,CAAC,EAC7D,QAAQ,EAAE,kBAAkB,CAAC,CAAC,CAAC,GAC9B,UAAU,CAoBZ;AAED;;;;GAIG;AACH,wBAAgB,YAAY,CAAC,CAAC,SAAS,MAAM,EAAE,QAAQ,EAAE,MAAM,CAAC,CAAC,CAAC,EAAE,SAAS,EAAE,CAAC,GAAG,SAAS,GAAG,MAAM,CAAC,CAAC,CAAC,CAGvG;AAED,oFAAoF;AACpF,MAAM,MAAM,MAAM,CAAC,CAAC,IAAI;KAAG,CAAC,IAAI,MAAM,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,SAAS,CAAC;CAAE,CAAA"}
package/dist/formParts.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
2
  import { useState } from "react";
3
- import { transportFailure } from "@supatype/client";
3
+ import { MissingClientValuesError, transportFailure } from "@supatype/client";
4
4
  import { errorProps } from "./classNames.js";
5
5
  /** The auth service's refusal, shown above the fields; nothing while there is none. */
6
6
  function FormError({ message, classNames, }) {
@@ -24,6 +24,17 @@ export function FormField({ id, label, classNames, ...input }) {
24
24
  export function FormShell({ request, text, className, classNames, errorMessage, children }) {
25
25
  return (_jsxs("form", { onSubmit: request.onSubmit, className: className, noValidate: true, children: [_jsx("h2", { className: classNames?.title, children: text.title }), _jsx(FormError, { message: errorMessage ?? request.errorMessage, classNames: classNames }), children, _jsx("button", { type: "submit", className: classNames?.submit, disabled: request.loading, children: request.loading ? text.busy : text.submit })] }));
26
26
  }
27
+ /**
28
+ * What a request that threw is shown as. A client with no address or anon key throws rather than
29
+ * answering, so that an app reading only `data` cannot miss it, and `transportFailure` rethrows it
30
+ * for the same reason; a form has somewhere to show it, so it becomes the form's error here.
31
+ */
32
+ function thrownError(err) {
33
+ // Already one of the family, so the form shows it as it is.
34
+ if (err instanceof MissingClientValuesError)
35
+ return err;
36
+ return transportFailure(err);
37
+ }
27
38
  /** The request's answer, with a request that threw (the network, not the server) as its refusal. */
28
39
  async function settle(send) {
29
40
  try {
@@ -31,7 +42,7 @@ async function settle(send) {
31
42
  return error === null ? { data, error } : { error };
32
43
  }
33
44
  catch (err) {
34
- return { error: transportFailure(err) };
45
+ return { error: thrownError(err) };
35
46
  }
36
47
  }
37
48
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"formParts.js","sourceRoot":"","sources":["../src/formParts.tsx"],"names":[],"mappings":";AAAA,OAAc,EAAE,QAAQ,EAA4C,MAAM,OAAO,CAAA;AACjF,OAAO,EAAE,gBAAgB,EAAsB,MAAM,kBAAkB,CAAA;AACvE,OAAO,EAAE,UAAU,EAA2B,MAAM,iBAAiB,CAAA;AAErE,uFAAuF;AACvF,SAAS,SAAS,CAAC,EACjB,OAAO,EACP,UAAU,GAIX;IACC,IAAI,OAAO,KAAK,IAAI;QAAE,OAAO,IAAI,CAAA;IACjC,OAAO,CACL,YAAG,IAAI,EAAC,OAAO,eAAW,QAAQ,KAAK,UAAU,CAAC,UAAU,CAAC,YAC1D,OAAO,GACN,CACL,CAAA;AACH,CAAC;AAED,+EAA+E;AAC/E,MAAM,UAAU,WAAW,CAAC,EAC1B,IAAI,EACJ,UAAU,GAIX;IACC,OAAO,CACL,YAAG,IAAI,EAAC,QAAQ,eAAW,QAAQ,EAAC,SAAS,EAAE,UAAU,EAAE,OAAO,YAC/D,IAAI,GACH,CACL,CAAA;AACH,CAAC;AAQD,qEAAqE;AACrE,MAAM,UAAU,SAAS,CAAC,EAAE,EAAE,EAAE,KAAK,EAAE,UAAU,EAAE,GAAG,KAAK,EAAkB;IAC3E,OAAO,CACL,eAAK,SAAS,EAAE,UAAU,EAAE,KAAK,aA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,CAAA;AACtD,CAAC"}
package/dist/index.d.ts CHANGED
@@ -12,5 +12,7 @@ export { usePasswordRecovery } from "./usePasswordRecovery.js";
12
12
  export type { PasswordRecovery } from "./usePasswordRecovery.js";
13
13
  export { OAuthButton } from "./OAuthButton.js";
14
14
  export type { OAuthButtonProps } from "./OAuthButton.js";
15
+ export { SSOForm } from "./SSOForm.js";
16
+ export type { SSOFormProps, SSOFormLabels } from "./SSOForm.js";
15
17
  export type { AuthFormClassNames } from "./classNames.js";
16
18
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAA;AAC1C,YAAY,EAAE,cAAc,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAA;AAErE,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAA;AAC5C,YAAY,EAAE,eAAe,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAA;AAExE,OAAO,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAA;AAC5D,YAAY,EAAE,uBAAuB,EAAE,wBAAwB,EAAE,MAAM,yBAAyB,CAAA;AAEhG,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAA;AAClD,YAAY,EAAE,kBAAkB,EAAE,mBAAmB,EAAE,MAAM,oBAAoB,CAAA;AAEjF,OAAO,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAA;AAC5D,YAAY,EAAE,uBAAuB,EAAE,wBAAwB,EAAE,MAAM,yBAAyB,CAAA;AAEhG,OAAO,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAA;AAC9D,YAAY,EAAE,gBAAgB,EAAE,MAAM,0BAA0B,CAAA;AAEhE,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAA;AAC9C,YAAY,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAA;AAExD,YAAY,EAAE,kBAAkB,EAAE,MAAM,iBAAiB,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAA;AAC1C,YAAY,EAAE,cAAc,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAA;AAErE,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAA;AAC5C,YAAY,EAAE,eAAe,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAA;AAExE,OAAO,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAA;AAC5D,YAAY,EAAE,uBAAuB,EAAE,wBAAwB,EAAE,MAAM,yBAAyB,CAAA;AAEhG,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAA;AAClD,YAAY,EAAE,kBAAkB,EAAE,mBAAmB,EAAE,MAAM,oBAAoB,CAAA;AAEjF,OAAO,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAA;AAC5D,YAAY,EAAE,uBAAuB,EAAE,wBAAwB,EAAE,MAAM,yBAAyB,CAAA;AAEhG,OAAO,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAA;AAC9D,YAAY,EAAE,gBAAgB,EAAE,MAAM,0BAA0B,CAAA;AAEhE,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAA;AAC9C,YAAY,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAA;AAExD,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAA;AACtC,YAAY,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,cAAc,CAAA;AAE/D,YAAY,EAAE,kBAAkB,EAAE,MAAM,iBAAiB,CAAA"}
package/dist/index.js CHANGED
@@ -5,4 +5,5 @@ export { MagicLinkForm } from "./MagicLinkForm.js";
5
5
  export { UpdatePasswordForm } from "./UpdatePasswordForm.js";
6
6
  export { usePasswordRecovery } from "./usePasswordRecovery.js";
7
7
  export { OAuthButton } from "./OAuthButton.js";
8
+ export { SSOForm } from "./SSOForm.js";
8
9
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAA;AAG1C,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAA;AAG5C,OAAO,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAA;AAG5D,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAA;AAGlD,OAAO,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAA;AAG5D,OAAO,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAA;AAG9D,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAA"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAA;AAG1C,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAA;AAG5C,OAAO,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAA;AAG5D,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAA;AAGlD,OAAO,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAA;AAG5D,OAAO,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAA;AAG9D,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAA;AAG9C,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAA"}
@@ -1 +1 @@
1
- {"version":3,"file":"usePasswordRecovery.d.ts","sourceRoot":"","sources":["../src/usePasswordRecovery.ts"],"names":[],"mappings":"AAGA,MAAM,WAAW,gBAAgB;IAC/B,iGAAiG;IACjG,MAAM,EAAE,OAAO,CAAA;IACf,wEAAwE;IACxE,MAAM,EAAE,MAAM,IAAI,CAAA;CACnB;AAED;;;;;;;;;GASG;AACH,wBAAgB,mBAAmB,IAAI,gBAAgB,CAWtD"}
1
+ {"version":3,"file":"usePasswordRecovery.d.ts","sourceRoot":"","sources":["../src/usePasswordRecovery.ts"],"names":[],"mappings":"AAGA,MAAM,WAAW,gBAAgB;IAC/B,iGAAiG;IACjG,MAAM,EAAE,OAAO,CAAA;IACf,wEAAwE;IACxE,MAAM,EAAE,MAAM,IAAI,CAAA;CACnB;AAED;;;;;;;;;GASG;AACH,wBAAgB,mBAAmB,IAAI,gBAAgB,CAatD"}
@@ -1,4 +1,4 @@
1
- import { useEffect, useState } from "react";
1
+ import { useCallback, useEffect, useState } from "react";
2
2
  import { useSupatype } from "@supatype/react";
3
3
  /**
4
4
  * Whether the user arrived through a password reset link and still has to choose a new password.
@@ -22,6 +22,8 @@ export function usePasswordRecovery() {
22
22
  });
23
23
  return () => data.subscription.unsubscribe();
24
24
  }, [client]);
25
- return { active, finish: () => setActive(false) };
25
+ // The same `finish` every render, so it can be an effect dependency (0.9.1 release test, RB10).
26
+ const finish = useCallback(() => setActive(false), []);
27
+ return { active, finish };
26
28
  }
27
29
  //# sourceMappingURL=usePasswordRecovery.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"usePasswordRecovery.js","sourceRoot":"","sources":["../src/usePasswordRecovery.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAA;AAC3C,OAAO,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAA;AAS7C;;;;;;;;;GASG;AACH,MAAM,UAAU,mBAAmB;IACjC,MAAM,MAAM,GAAG,WAAW,EAAE,CAAA;IAC5B,MAAM,CAAC,MAAM,EAAE,SAAS,CAAC,GAAG,QAAQ,CAAC,KAAK,CAAC,CAAA;IAC3C,SAAS,CAAC,GAAG,EAAE;QACb,MAAM,EAAE,IAAI,EAAE,GAAG,MAAM,CAAC,IAAI,CAAC,iBA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G,MAAM,MAAM,GAAG,WAAW,CAAC,GAAG,EAAE,CAAC,SAAS,CAAC,KAAK,CAAC,EAAE,EAAE,CAAC,CAAA;IACtD,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,CAAA;AAC3B,CAAC"}
@@ -0,0 +1,8 @@
1
+ import type { AuthRedirectError } from "@supatype/client";
2
+ /**
3
+ * The sign-in the auth server refused and sent back in the page's URL, when `provider` started it,
4
+ * else null. `onError` hears it once, through a ref so an inline handler does not hear it again on
5
+ * every render.
6
+ */
7
+ export declare function useRedirectError(provider: string, onError: ((error: AuthRedirectError) => void) | undefined): AuthRedirectError | null;
8
+ //# sourceMappingURL=useRedirectError.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useRedirectError.d.ts","sourceRoot":"","sources":["../src/useRedirectError.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAA;AAGzD;;;;GAIG;AACH,wBAAgB,gBAAgB,CAC9B,QAAQ,EAAE,MAAM,EAChB,OAAO,EAAE,CAAC,CAAC,KAAK,EAAE,iBAAiB,KAAK,IAAI,CAAC,GAAG,SAAS,GACxD,iBAAiB,GAAG,IAAI,CAS1B"}
@@ -0,0 +1,19 @@
1
+ import { useEffect, useRef } from "react";
2
+ import { useAuth } from "@supatype/react";
3
+ /**
4
+ * The sign-in the auth server refused and sent back in the page's URL, when `provider` started it,
5
+ * else null. `onError` hears it once, through a ref so an inline handler does not hear it again on
6
+ * every render.
7
+ */
8
+ export function useRedirectError(provider, onError) {
9
+ const { error } = useAuth();
10
+ const onErrorRef = useRef(onError);
11
+ onErrorRef.current = onError;
12
+ const mine = error !== null && error.provider === provider ? error : null;
13
+ useEffect(() => {
14
+ if (mine !== null)
15
+ onErrorRef.current?.(mine);
16
+ }, [mine]);
17
+ return mine;
18
+ }
19
+ //# sourceMappingURL=useRedirectError.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useRedirectError.js","sourceRoot":"","sources":["../src/useRedirectError.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,EAAE,MAAM,OAAO,CAAA;AAEzC,OAAO,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAA;AAEzC;;;;GAIG;AACH,MAAM,UAAU,gBAAgB,CAC9B,QAAgB,EAChB,OAAyD;IAEzD,MAAM,EAAE,KAAK,EAAE,GAAG,OAAO,EAAE,CAAA;IAC3B,MAAM,UAAU,GAAG,MAAM,CAAC,OAAO,CAAC,CAAA;IAClC,UAAU,CAAC,OAAO,GAAG,OAAO,CAAA;IAC5B,MAAM,IAAI,GAAG,KAAK,KAAK,IAAI,IAAI,KAAK,CAAC,QAAQ,KAAK,QAAQ,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,CAAA;IACzE,SAAS,CAAC,GAAG,EAAE;QACb,IAAI,IAAI,KAAK,IAAI;YAAE,UAAU,CAAC,OAAO,EAAE,CAAC,IAAI,CAAC,CAAA;IAC/C,CAAC,EAAE,CAAC,IAAI,CAAC,CAAC,CAAA;IACV,OAAO,IAAI,CAAA;AACb,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@supatype/react-auth",
3
- "version": "0.9.0",
3
+ "version": "0.9.2",
4
4
  "license": "MIT",
5
5
  "description": "Pre-built authentication UI components for Supatype",
6
6
  "type": "module",
@@ -13,8 +13,8 @@
13
13
  }
14
14
  },
15
15
  "dependencies": {
16
- "@supatype/client": "0.9.0",
17
- "@supatype/react": "0.9.0"
16
+ "@supatype/react": "0.9.2",
17
+ "@supatype/client": "0.9.2"
18
18
  },
19
19
  "peerDependencies": {
20
20
  "react": ">=18"
@@ -12,8 +12,9 @@
12
12
  * ```
13
13
  */
14
14
 
15
- import React, { useEffect, useRef, useState, type ReactNode } from "react"
15
+ import React, { useState, type ReactNode } from "react"
16
16
  import { useAuth } from "@supatype/react"
17
+ import { useRedirectError } from "./useRedirectError.js"
17
18
 
18
19
  export interface OAuthButtonProps {
19
20
  /** OAuth provider name (e.g. "github", "google", "apple"). */
@@ -87,20 +88,6 @@ function defaultStyle(busy: boolean): React.CSSProperties {
87
88
  }
88
89
  }
89
90
 
90
- /**
91
- * Report a refusal the auth server sent back in the URL, when this button's provider started it.
92
- *
93
- * Through a ref so an inline `onError` does not report the same refusal on every render.
94
- */
95
- function useRedirectError(provider: string, onError: OAuthButtonProps["onError"]): void {
96
- const { error } = useAuth()
97
- const onErrorRef = useRef(onError)
98
- onErrorRef.current = onError
99
- useEffect(() => {
100
- if (error !== null && error.provider === provider) onErrorRef.current?.(error)
101
- }, [error, provider])
102
- }
103
-
104
91
  /**
105
92
  * The button's click: ask for the provider's URL and go there, or report why not.
106
93
  *
@@ -0,0 +1,94 @@
1
+ import React, { useState } from "react"
2
+ import { SSO_PROVIDER, SupatypeError, ssoDomain, type AuthClient, type SignInWithSSOResult } from "@supatype/client"
3
+ import { useSupatype } from "@supatype/react"
4
+ import type { AuthFormClassNames } from "./classNames.js"
5
+ import { FormField, FormShell, FormMessage, useAuthSubmit, withDefaults, type Filled } from "./formParts.js"
6
+ import { useRedirectError } from "./useRedirectError.js"
7
+
8
+ export interface SSOFormLabels {
9
+ title?: string | undefined
10
+ email?: string | undefined
11
+ submit?: string | undefined
12
+ /** Shown in place of the form while the browser goes to the identity provider. */
13
+ successMessage?: string | undefined
14
+ }
15
+
16
+ export interface SSOFormProps {
17
+ /** Where the browser lands once the identity provider has signed the user in. */
18
+ redirectTo?: string | undefined
19
+ /** Called with the identity provider's URL as the browser is sent there. */
20
+ onSuccess?: ((url: string) => void) | undefined
21
+ /** Called with the error returned by the auth service, or the form's own refusal of the address. */
22
+ onError?: ((error: SupatypeError) => void) | undefined
23
+ /** CSS class applied to the outermost <form> element. */
24
+ className?: string | undefined
25
+ /** Override display labels. */
26
+ labels?: SSOFormLabels | undefined
27
+ /** Class names for the elements inside the form, so an app can style them with its own classes. */
28
+ classNames?: AuthFormClassNames | undefined
29
+ }
30
+
31
+ const DEFAULT_LABELS: Filled<SSOFormLabels> = {
32
+ title: "Sign in with SSO",
33
+ email: "Work email",
34
+ submit: "Continue with SSO",
35
+ successMessage: "Redirecting to your identity provider…",
36
+ }
37
+
38
+ const NO_DOMAIN = "Enter your work email address."
39
+
40
+ /** Start SSO for the address typed, refusing one with no domain before the server is asked. */
41
+ function startSSO(auth: AuthClient, email: string, redirectTo: string | undefined): Promise<SignInWithSSOResult> {
42
+ const domain = ssoDomain(email)
43
+ if (domain === null) {
44
+ const error = new SupatypeError({ message: NO_DOMAIN, code: "validation_failed" })
45
+ return Promise.resolve({ data: { url: "" }, error })
46
+ }
47
+ return auth.signInWithSSO({ domain, ...(redirectTo !== undefined && { options: { redirectTo } }) })
48
+ }
49
+
50
+ /**
51
+ * Signs the user in through their organisation's SAML identity provider, found by the domain of
52
+ * the email they type (`signInWithSSO`, `POST /sso`). Must be rendered inside a `<SupatypeProvider>`.
53
+ *
54
+ * The browser goes to the identity provider and comes back signed in on `redirectTo` (honoured on
55
+ * the site URL's host or the auth server's redirect allow list, else the site URL). A sign-in the
56
+ * server refused on the way back is shown above the field and passed to `onError`.
57
+ *
58
+ * @example
59
+ * ```tsx
60
+ * <SSOForm redirectTo={window.location.origin} />
61
+ * ```
62
+ */
63
+ export function SSOForm(props: SSOFormProps): React.ReactElement {
64
+ const { auth } = useSupatype()
65
+ const { redirectTo, onSuccess, onError, className, classNames } = props
66
+ const l = withDefaults(DEFAULT_LABELS, props.labels)
67
+ const [email, setEmail] = useState("")
68
+ const redirectError = useRedirectError(SSO_PROVIDER, onError)
69
+ const request = useAuthSubmit(() => startSSO(auth, email, redirectTo), { onDone: (data) => onSuccess?.(data.url), onError })
70
+
71
+ if (request.done) return <FormMessage text={l.successMessage} classNames={classNames} />
72
+
73
+ return (
74
+ <FormShell
75
+ request={request}
76
+ text={{ title: l.title, submit: l.submit, busy: "Redirecting…" }}
77
+ className={className}
78
+ classNames={classNames}
79
+ errorMessage={request.errorMessage ?? redirectError?.message}
80
+ >
81
+ <FormField
82
+ id="st-sso-email"
83
+ label={l.email}
84
+ classNames={classNames}
85
+ type="email"
86
+ autoComplete="email"
87
+ required
88
+ value={email}
89
+ onChange={(e) => setEmail(e.target.value)}
90
+ disabled={request.loading}
91
+ />
92
+ </FormShell>
93
+ )
94
+ }
package/src/formParts.tsx CHANGED
@@ -1,5 +1,5 @@
1
1
  import React, { useState, type FormEvent, type InputHTMLAttributes } from "react"
2
- import { transportFailure, type SupatypeError } from "@supatype/client"
2
+ import { MissingClientValuesError, transportFailure, type SupatypeError } from "@supatype/client"
3
3
  import { errorProps, type AuthFormClassNames } from "./classNames.js"
4
4
 
5
5
  /** The auth service's refusal, shown above the fields; nothing while there is none. */
@@ -97,13 +97,24 @@ export interface AuthSubmitHandlers<T> {
97
97
 
98
98
  type Settled<T> = { data: T; error: null } | { error: SupatypeError }
99
99
 
100
+ /**
101
+ * What a request that threw is shown as. A client with no address or anon key throws rather than
102
+ * answering, so that an app reading only `data` cannot miss it, and `transportFailure` rethrows it
103
+ * for the same reason; a form has somewhere to show it, so it becomes the form's error here.
104
+ */
105
+ function thrownError(err: unknown): SupatypeError {
106
+ // Already one of the family, so the form shows it as it is.
107
+ if (err instanceof MissingClientValuesError) return err
108
+ return transportFailure(err)
109
+ }
110
+
100
111
  /** The request's answer, with a request that threw (the network, not the server) as its refusal. */
101
112
  async function settle<T>(send: () => Promise<{ data: T; error: SupatypeError | null }>): Promise<Settled<T>> {
102
113
  try {
103
114
  const { data, error } = await send()
104
115
  return error === null ? { data, error } : { error }
105
116
  } catch (err) {
106
- return { error: transportFailure(err) }
117
+ return { error: thrownError(err) }
107
118
  }
108
119
  }
109
120
 
package/src/index.ts CHANGED
@@ -19,4 +19,7 @@ export type { PasswordRecovery } from "./usePasswordRecovery.js"
19
19
  export { OAuthButton } from "./OAuthButton.js"
20
20
  export type { OAuthButtonProps } from "./OAuthButton.js"
21
21
 
22
+ export { SSOForm } from "./SSOForm.js"
23
+ export type { SSOFormProps, SSOFormLabels } from "./SSOForm.js"
24
+
22
25
  export type { AuthFormClassNames } from "./classNames.js"
@@ -1,4 +1,4 @@
1
- import { useEffect, useState } from "react"
1
+ import { useCallback, useEffect, useState } from "react"
2
2
  import { useSupatype } from "@supatype/react"
3
3
 
4
4
  export interface PasswordRecovery {
@@ -28,5 +28,7 @@ export function usePasswordRecovery(): PasswordRecovery {
28
28
  })
29
29
  return () => data.subscription.unsubscribe()
30
30
  }, [client])
31
- return { active, finish: () => setActive(false) }
31
+ // The same `finish` every render, so it can be an effect dependency (0.9.1 release test, RB10).
32
+ const finish = useCallback(() => setActive(false), [])
33
+ return { active, finish }
32
34
  }