@udibo/oauth2 0.54.0 → 0.55.1

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.
@@ -0,0 +1,212 @@
1
+ /**
2
+ * {@link LinkedAccounts} — a default, accessible, unstyled list of the social
3
+ * and federated accounts linked to an account, with "Disconnect" on each and
4
+ * "Connect …" for the providers it can still link. The accounts come in as
5
+ * data and each action goes out through a callback; the component never loads,
6
+ * links or unlinks anything itself.
7
+ *
8
+ * @module
9
+ */
10
+ import type { ReactNode } from "react";
11
+ import type { AccountActionHandler, BaseClassNames, SocialProvider } from "./types.ts";
12
+ /** One linked account, as {@link LinkedAccounts} renders it. */
13
+ export interface LinkedAccount {
14
+ /**
15
+ * The link's identifier: an opaque, non-secret id such as a public row id,
16
+ * never a provider token. It is handed back to `onUnlink`, and although it
17
+ * is not displayed as text, it is written into the page — `data-oauth2-*`
18
+ * attributes and the hidden `identityId` input a no-JavaScript submit posts.
19
+ */
20
+ id: string;
21
+ /** The provider's name, such as `"GitHub"`. */
22
+ providerName: string;
23
+ /** The email address the provider reported for this account. */
24
+ email?: string | null;
25
+ /** When the account was linked. */
26
+ linkedAt?: Date;
27
+ /**
28
+ * Set `false` when disconnecting this account would leave no way to sign in,
29
+ * so the row shows the `lastMethod` text instead of a "Disconnect" button.
30
+ * Your server must still refuse that unlink: this only keeps the button
31
+ * from being offered.
32
+ */
33
+ canUnlink?: boolean;
34
+ }
35
+ /**
36
+ * Per-slot class hooks for {@link LinkedAccounts}: the shared
37
+ * {@link BaseClassNames} `root` plus the list's own slots. Each element also
38
+ * carries the stable `data-oauth2-*` attribute named here.
39
+ */
40
+ export interface LinkedAccountsClassNames extends BaseClassNames {
41
+ /** The `<ul>` of linked accounts (`data-oauth2-linked-account-items`). */
42
+ list?: string;
43
+ /** Each `<li>` (`data-oauth2-linked-account`, whose value is the link id). */
44
+ item?: string;
45
+ /** The provider name of each account (`data-oauth2-linked-account-name`). */
46
+ name?: string;
47
+ /** The email and date line under the name (`data-oauth2-linked-account-meta`). */
48
+ meta?: string;
49
+ /** Each "Disconnect" button (`data-oauth2-unlink`). */
50
+ unlink?: string;
51
+ /**
52
+ * The text shown in place of "Disconnect" on an account that cannot be
53
+ * unlinked (`data-oauth2-last-method`).
54
+ */
55
+ hint?: string;
56
+ /** The wrapper of the "Connect …" controls (`data-oauth2-connect`). */
57
+ connectSection?: string;
58
+ /** Each "Connect …" button or link (`data-oauth2-connect-button`). */
59
+ connectButton?: string;
60
+ /** The error summary shown after a failed action (`data-oauth2-error-summary`). */
61
+ errorSummary?: string;
62
+ /** The text shown when no account is linked (`data-oauth2-empty`). */
63
+ empty?: string;
64
+ }
65
+ /** Visible text overrides for {@link LinkedAccounts}. */
66
+ export interface LinkedAccountsLabels {
67
+ /** Prefix of the linked date. Default: `"Connected"`. */
68
+ linked?: string;
69
+ /**
70
+ * "Disconnect" button text. Default: `"Disconnect"`. Its accessible name adds
71
+ * the provider, such as "Disconnect GitHub".
72
+ */
73
+ unlink?: string;
74
+ /** "Disconnect" button text while pending. Default: `"Disconnecting…"`. */
75
+ unlinking?: string;
76
+ /**
77
+ * Text before a provider's name on its connect control. Default:
78
+ * `"Connect"`, rendering "Connect GitHub".
79
+ */
80
+ link?: string;
81
+ /** Connect button text while pending. Default: `"Connecting…"`. */
82
+ linking?: string;
83
+ /**
84
+ * Shown on an account whose `canUnlink` is `false`. Default:
85
+ * `"This is your only way to sign in, so it can't be disconnected."`.
86
+ */
87
+ lastMethod?: string;
88
+ /** Shown when `accounts` is empty. Default: `"No accounts connected yet."`. */
89
+ empty?: string;
90
+ }
91
+ /**
92
+ * The live state {@link LinkedAccounts} hands to a render-prop `children`:
93
+ * the data, which action is pending, the last error, and the two actions with
94
+ * the component's single-flight guard applied.
95
+ */
96
+ export interface LinkedAccountsState {
97
+ /** The linked accounts passed to the component. */
98
+ accounts: readonly LinkedAccount[];
99
+ /** The providers passed to the component. */
100
+ providers: readonly SocialProvider[];
101
+ /** The id of the account whose unlink is pending, else `null`. */
102
+ pendingAccountId: string | null;
103
+ /** The id of the provider whose link is pending, else `null`. */
104
+ pendingProviderId: string | null;
105
+ /** The message from the last failed action, else `null`. */
106
+ error: string | null;
107
+ /**
108
+ * Runs `onUnlink` for an account. Ignored while any action is pending, when
109
+ * `onUnlink` was not passed, or when the account's `canUnlink` is `false`.
110
+ */
111
+ unlink(account: LinkedAccount): Promise<void>;
112
+ /**
113
+ * Runs `onLink` for a provider. Ignored while any action is pending or when
114
+ * `onLink` was not passed.
115
+ */
116
+ link(provider: SocialProvider): Promise<void>;
117
+ }
118
+ /** Props for {@link LinkedAccounts}. */
119
+ export interface LinkedAccountsProps {
120
+ /** The accounts linked to this account, in the order to list them. */
121
+ accounts: readonly LinkedAccount[];
122
+ /**
123
+ * Disconnects one linked account. Omit it for a read-only list. Refuse an
124
+ * unlink that would leave no way to sign in on your server, whatever
125
+ * `canUnlink` says.
126
+ */
127
+ onUnlink?: AccountActionHandler<LinkedAccount>;
128
+ /**
129
+ * Providers the account can still link. Each gets a "Connect …" control
130
+ * when `onLink` or `linkHref` is passed. Empty or absent renders no connect
131
+ * section.
132
+ */
133
+ providers?: readonly SocialProvider[];
134
+ /**
135
+ * Starts linking a provider. Its pending label shows until the returned
136
+ * promise settles; a flow that navigates away can simply not resolve.
137
+ */
138
+ onLink?: AccountActionHandler<SocialProvider>;
139
+ /**
140
+ * Builds the href that starts linking a provider, rendering links instead of
141
+ * buttons. Wins over `onLink` when both are passed.
142
+ */
143
+ linkHref?: (provider: SocialProvider) => string;
144
+ /**
145
+ * Formats `linkedAt`. Defaults to the runtime's locale and time zone, which
146
+ * can differ between server and browser; pass a formatter with a fixed
147
+ * locale and `timeZone` on a server-rendered page so hydration matches.
148
+ */
149
+ formatDate?: (date: Date) => string;
150
+ /**
151
+ * `action` for each "Disconnect" button's `<form>`. Set it on a
152
+ * server-rendered page so the button still posts when JavaScript never
153
+ * arrives, with `intent=unlink-identity` and `identityId`. Once React is
154
+ * running, `onUnlink` handles the submit and the native post is
155
+ * suppressed. The forms always use `post`. A native post cannot carry a
156
+ * CSRF header, so check `Origin` or `Sec-Fetch-Site` on the route that
157
+ * receives it. Connect controls never post: use `linkHref` for a link that
158
+ * works without JavaScript.
159
+ */
160
+ action?: string;
161
+ /** Class for the root wrapper (merged with `classNames.root`). */
162
+ className?: string;
163
+ /** Per-slot class hooks for theming. See {@link LinkedAccountsClassNames}. */
164
+ classNames?: LinkedAccountsClassNames;
165
+ /** Text overrides. */
166
+ labels?: LinkedAccountsLabels;
167
+ /**
168
+ * Render-prop escape hatch. When provided, you own the markup and receive
169
+ * the live {@link LinkedAccountsState}; the component still owns the
170
+ * pending and error state.
171
+ */
172
+ children?: (state: LinkedAccountsState) => ReactNode;
173
+ }
174
+ /**
175
+ * A ready-to-use list of the social and federated accounts linked to an
176
+ * account. Pass the accounts your loader read and wire `onUnlink` to your
177
+ * server; pass `providers` with `onLink` or `linkHref` to offer the ones not
178
+ * yet linked. After an action succeeds, pass the updated data so the list
179
+ * follows.
180
+ *
181
+ * Set `canUnlink: false` on an account that is the last way to sign in. A
182
+ * failed action shows its message in an error summary that takes focus, and a
183
+ * pending button keeps focus with `aria-disabled="true"`.
184
+ *
185
+ * @example
186
+ * ```tsx
187
+ * import {
188
+ * type LinkedAccount,
189
+ * LinkedAccounts,
190
+ * } from "@udibo/oauth2/react/components";
191
+ *
192
+ * function Connected(props: { accounts: LinkedAccount[]; hasPassword: boolean }) {
193
+ * return (
194
+ * <LinkedAccounts
195
+ * accounts={props.accounts.map((account) => ({
196
+ * ...account,
197
+ * canUnlink: props.hasPassword || props.accounts.length > 1,
198
+ * }))}
199
+ * onUnlink={async (account) => {
200
+ * const response = await fetch(`/account/identities/${account.id}`, {
201
+ * method: "DELETE",
202
+ * });
203
+ * if (!response.ok) return { error: "Couldn't disconnect that account." };
204
+ * }}
205
+ * providers={[{ id: "github", name: "GitHub" }]}
206
+ * linkHref={(provider) => `/auth/link/${provider.id}`}
207
+ * />
208
+ * );
209
+ * }
210
+ * ```
211
+ */
212
+ export declare function LinkedAccounts(props: LinkedAccountsProps): ReactNode;
@@ -0,0 +1,98 @@
1
+ import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { AccountActionError, ActionForm, formatAccountDate, useAccountAction, useFocusAfterRemoval, } from "./account-internal.js";
3
+ import { combineClassNames } from "./internal.js";
4
+ const LINK_KEY_PREFIX = "\u0000link:";
5
+ /**
6
+ * A ready-to-use list of the social and federated accounts linked to an
7
+ * account. Pass the accounts your loader read and wire `onUnlink` to your
8
+ * server; pass `providers` with `onLink` or `linkHref` to offer the ones not
9
+ * yet linked. After an action succeeds, pass the updated data so the list
10
+ * follows.
11
+ *
12
+ * Set `canUnlink: false` on an account that is the last way to sign in. A
13
+ * failed action shows its message in an error summary that takes focus, and a
14
+ * pending button keeps focus with `aria-disabled="true"`.
15
+ *
16
+ * @example
17
+ * ```tsx
18
+ * import {
19
+ * type LinkedAccount,
20
+ * LinkedAccounts,
21
+ * } from "@udibo/oauth2/react/components";
22
+ *
23
+ * function Connected(props: { accounts: LinkedAccount[]; hasPassword: boolean }) {
24
+ * return (
25
+ * <LinkedAccounts
26
+ * accounts={props.accounts.map((account) => ({
27
+ * ...account,
28
+ * canUnlink: props.hasPassword || props.accounts.length > 1,
29
+ * }))}
30
+ * onUnlink={async (account) => {
31
+ * const response = await fetch(`/account/identities/${account.id}`, {
32
+ * method: "DELETE",
33
+ * });
34
+ * if (!response.ok) return { error: "Couldn't disconnect that account." };
35
+ * }}
36
+ * providers={[{ id: "github", name: "GitHub" }]}
37
+ * linkHref={(provider) => `/auth/link/${provider.id}`}
38
+ * />
39
+ * );
40
+ * }
41
+ * ```
42
+ */
43
+ export function LinkedAccounts(props) {
44
+ const { accounts, onUnlink, providers = [], onLink, linkHref, formatDate = formatAccountDate, action, className, classNames, labels, children, } = props;
45
+ const runner = useAccountAction();
46
+ const rootRef = useFocusAfterRemoval(runner, accounts);
47
+ const unlink = async (account) => {
48
+ if (!onUnlink || account.canUnlink === false)
49
+ return;
50
+ await runner.run(account.id, () => onUnlink(account));
51
+ };
52
+ const link = async (provider) => {
53
+ if (!onLink)
54
+ return;
55
+ await runner.run(LINK_KEY_PREFIX + provider.id, () => onLink(provider));
56
+ };
57
+ const pendingProviderId = runner.pendingKey?.startsWith(LINK_KEY_PREFIX)
58
+ ? runner.pendingKey.slice(LINK_KEY_PREFIX.length)
59
+ : null;
60
+ const pendingAccountId = pendingProviderId === null ? runner.pendingKey : null;
61
+ if (children) {
62
+ return (_jsx(_Fragment, { children: children({
63
+ accounts,
64
+ providers,
65
+ pendingAccountId,
66
+ pendingProviderId,
67
+ error: runner.error,
68
+ unlink,
69
+ link,
70
+ }) }));
71
+ }
72
+ const linkText = labels?.link ?? "Connect";
73
+ const showConnect = providers.length > 0 && Boolean(linkHref || onLink);
74
+ return (_jsxs("div", { ref: rootRef, tabIndex: -1, "data-oauth2-linked-accounts": "", className: combineClassNames(className, classNames?.root), children: [_jsx(AccountActionError, { error: runner.error, className: classNames?.errorSummary }), accounts.length === 0 ? (_jsx("p", { "data-oauth2-empty": "", className: classNames?.empty, children: labels?.empty ?? "No accounts connected yet." })) : (_jsx("ul", { "data-oauth2-linked-account-items": "", className: classNames?.list, children: accounts.map((account) => {
75
+ const meta = [
76
+ account.email || null,
77
+ account.linkedAt
78
+ ? `${labels?.linked ?? "Connected"} ${formatDate(account.linkedAt)}`
79
+ : null,
80
+ ].filter((part) => part !== null);
81
+ return (_jsxs("li", { "data-oauth2-linked-account": account.id, className: classNames?.item, children: [_jsx("span", { "data-oauth2-linked-account-name": "", className: classNames?.name, children: account.providerName }), meta.length > 0 ? (_jsx("span", { "data-oauth2-linked-account-meta": "", className: classNames?.meta, children: meta.join(" · ") })) : null, onUnlink && account.canUnlink === false ? (_jsx("span", { "data-oauth2-last-method": "", className: classNames?.hint, children: labels?.lastMethod ??
82
+ "This is your only way to sign in, so it can't be disconnected." })) : null, onUnlink && account.canUnlink !== false ? (_jsx(ActionForm, { fields: {
83
+ intent: "unlink-identity",
84
+ identityId: account.id,
85
+ }, action: action, onActivate: () => {
86
+ void unlink(account);
87
+ }, pending: pendingAccountId === account.id, label: labels?.unlink ?? "Disconnect", pendingLabel: labels?.unlinking ?? "Disconnecting…", accessibleName: account.providerName, dataAttribute: "data-oauth2-unlink", dataValue: account.id, className: classNames?.unlink })) : null] }, account.id));
88
+ }) })), showConnect ? (_jsx("div", { "data-oauth2-connect": "", className: classNames?.connectSection, children: providers.map((provider) => {
89
+ const content = (_jsxs(_Fragment, { children: [provider.iconSlot ? (_jsx("span", { "data-oauth2-social-icon": "", children: provider.iconSlot })) : null, _jsx("span", { "data-oauth2-social-label": "", children: pendingProviderId === provider.id
90
+ ? (labels?.linking ?? "Connecting…")
91
+ : `${linkText} ${provider.name}` })] }));
92
+ return linkHref ? (_jsx("a", { href: linkHref(provider), "data-oauth2-connect-button": provider.id, className: classNames?.connectButton, children: content }, provider.id)) : (_jsx("button", { type: "button", "aria-disabled": pendingProviderId === provider.id ? true : undefined, "aria-label": pendingProviderId === provider.id
93
+ ? `${labels?.linking ?? "Connecting…"} ${provider.name}`
94
+ : undefined, onClick: () => {
95
+ void link(provider);
96
+ }, "data-oauth2-connect-button": provider.id, className: classNames?.connectButton, children: content }, provider.id));
97
+ }) })) : null] }));
98
+ }
@@ -16,6 +16,11 @@
16
16
  * {@link RequestPasswordResetForm}, {@link ResetPasswordForm},
17
17
  * {@link MfaEnrollmentForm}, {@link MfaChallengeForm}, {@link UserMenu} —
18
18
  * render accessible markup with class hooks.
19
+ * - **Account components** — {@link SessionList}, {@link LinkedAccounts} and
20
+ * {@link ChangePasswordForm} — the signed-in half: the sessions and linked
21
+ * accounts come in as props, and each action goes out through a callback
22
+ * ({@link AccountActionHandler}) or `onSubmit`. They are a small set for an
23
+ * account page you build, not a profile page of their own.
19
24
  * - **Headless** — {@link useAuthForm} owns values, errors, and the submit
20
25
  * lifecycle with no markup. Every default component is built on it; "eject"
21
26
  * by using the hook directly, or by passing a function as a component's
@@ -26,8 +31,10 @@
26
31
  *
27
32
  * ## Server-rendered pages
28
33
  *
29
- * Pass `action` + `method` and the rendered `<form>` carries them, so a
30
- * server-rendered page still posts when JavaScript never arrives — every
34
+ * Every rendered `<form>` uses `method="post"` unless you pass `method`, so a
35
+ * submit before React hydrates never puts credentials in the URL. Pass
36
+ * `action` and the form carries it, so a server-rendered page still posts to
37
+ * that route when JavaScript never arrives — every
31
38
  * rendered field carries its `name`, so the native post sends those fields
32
39
  * under the keys `onSubmit` receives. Values a form holds without rendering a
33
40
  * field for them are absent from a native post: `ResetPasswordForm`'s
@@ -85,7 +92,7 @@
85
92
  */
86
93
  export { useAuthForm } from "./use-auth-form.ts";
87
94
  export type { AuthFieldProps, AuthFormState, AuthFormStatus, UseAuthFormOptions, } from "./use-auth-form.ts";
88
- export type { AuthFormClassNames, AuthFormErrors, AuthFormResult, AuthFormValues, AuthSubmitHandler, BaseAuthFormProps, BaseClassNames, PasskeyOption, SocialProvider, SocialProvidersProps, } from "./types.ts";
95
+ export type { AccountActionHandler, AccountActionResult, AuthFormClassNames, AuthFormErrors, AuthFormResult, AuthFormValues, AuthSubmitHandler, BaseAuthFormProps, BaseClassNames, PasskeyOption, SocialProvider, SocialProvidersProps, } from "./types.ts";
89
96
  export { AuthFormClassNamesProvider, useAuthFormClassNames, } from "./class-names.tsx";
90
97
  export type { AuthFormClassNamesProviderProps } from "./class-names.tsx";
91
98
  export { SignInForm } from "./sign-in-form.tsx";
@@ -102,3 +109,9 @@ export { MfaChallengeForm } from "./mfa-challenge-form.tsx";
102
109
  export type { MfaChallengeFormProps, MfaChallengeLabels, MfaChallengeMethod, MfaChallengeValues, } from "./mfa-challenge-form.tsx";
103
110
  export { UserMenu } from "./user-menu.tsx";
104
111
  export type { UserMenuClassNames, UserMenuLabels, UserMenuProps, } from "./user-menu.tsx";
112
+ export { SessionList } from "./session-list.tsx";
113
+ export type { SessionListClassNames, SessionListItem, SessionListLabels, SessionListProps, SessionListState, } from "./session-list.tsx";
114
+ export { LinkedAccounts } from "./linked-accounts.tsx";
115
+ export type { LinkedAccount, LinkedAccountsClassNames, LinkedAccountsLabels, LinkedAccountsProps, LinkedAccountsState, } from "./linked-accounts.tsx";
116
+ export { ChangePasswordForm } from "./change-password-form.tsx";
117
+ export type { ChangePasswordFormProps, ChangePasswordLabels, ChangePasswordValues, } from "./change-password-form.tsx";
@@ -16,6 +16,11 @@
16
16
  * {@link RequestPasswordResetForm}, {@link ResetPasswordForm},
17
17
  * {@link MfaEnrollmentForm}, {@link MfaChallengeForm}, {@link UserMenu} —
18
18
  * render accessible markup with class hooks.
19
+ * - **Account components** — {@link SessionList}, {@link LinkedAccounts} and
20
+ * {@link ChangePasswordForm} — the signed-in half: the sessions and linked
21
+ * accounts come in as props, and each action goes out through a callback
22
+ * ({@link AccountActionHandler}) or `onSubmit`. They are a small set for an
23
+ * account page you build, not a profile page of their own.
19
24
  * - **Headless** — {@link useAuthForm} owns values, errors, and the submit
20
25
  * lifecycle with no markup. Every default component is built on it; "eject"
21
26
  * by using the hook directly, or by passing a function as a component's
@@ -26,8 +31,10 @@
26
31
  *
27
32
  * ## Server-rendered pages
28
33
  *
29
- * Pass `action` + `method` and the rendered `<form>` carries them, so a
30
- * server-rendered page still posts when JavaScript never arrives — every
34
+ * Every rendered `<form>` uses `method="post"` unless you pass `method`, so a
35
+ * submit before React hydrates never puts credentials in the URL. Pass
36
+ * `action` and the form carries it, so a server-rendered page still posts to
37
+ * that route when JavaScript never arrives — every
31
38
  * rendered field carries its `name`, so the native post sends those fields
32
39
  * under the keys `onSubmit` receives. Values a form holds without rendering a
33
40
  * field for them are absent from a native post: `ResetPasswordForm`'s
@@ -92,3 +99,6 @@ export { ResetPasswordForm } from "./reset-password-form.js";
92
99
  export { MfaEnrollmentForm } from "./mfa-enrollment-form.js";
93
100
  export { MfaChallengeForm } from "./mfa-challenge-form.js";
94
101
  export { UserMenu } from "./user-menu.js";
102
+ export { SessionList } from "./session-list.js";
103
+ export { LinkedAccounts } from "./linked-accounts.js";
104
+ export { ChangePasswordForm } from "./change-password-form.js";
@@ -0,0 +1,204 @@
1
+ /**
2
+ * {@link SessionList} — a default, accessible, unstyled list of the places an
3
+ * account is signed in, with "Sign out" on each other session and "Sign out
4
+ * everywhere else". The sessions come in as data and each action goes out
5
+ * through a callback; the component never loads or revokes anything itself.
6
+ *
7
+ * @module
8
+ */
9
+ import type { ReactNode } from "react";
10
+ import type { AccountActionHandler, AccountActionResult, BaseClassNames } from "./types.ts";
11
+ /** One signed-in session, as {@link SessionList} renders it. */
12
+ export interface SessionListItem {
13
+ /**
14
+ * The session's identifier: an opaque, non-secret id such as a public row
15
+ * id, **never the session token or cookie value**. It is handed back to
16
+ * `onRevoke`, and although it is not displayed as text, it is written into
17
+ * the page — `data-oauth2-*` attributes and the hidden `sessionId` input a
18
+ * no-JavaScript submit posts.
19
+ */
20
+ id: string;
21
+ /**
22
+ * `true` for the session making this request. It is badged, listed with the
23
+ * others, and never offered a "Sign out" button: signing yourself out is
24
+ * the sign-out action's job.
25
+ */
26
+ current?: boolean;
27
+ /**
28
+ * What the person recognizes the session by, such as `"Firefox on Linux"`.
29
+ * Summarize the user agent on your server; the component shows this text as
30
+ * given, or the `unknownDevice` label when it is absent.
31
+ */
32
+ device?: string | null;
33
+ /** The IP address the session was last seen from. */
34
+ ipAddress?: string | null;
35
+ /** When the session signed in. */
36
+ createdAt?: Date;
37
+ /** When the session was last used. */
38
+ lastActiveAt?: Date;
39
+ }
40
+ /**
41
+ * Per-slot class hooks for {@link SessionList}: the shared
42
+ * {@link BaseClassNames} `root` plus the list's own slots. Each element also
43
+ * carries the stable `data-oauth2-*` attribute named here.
44
+ */
45
+ export interface SessionListClassNames extends BaseClassNames {
46
+ /** The `<ul>` of sessions (`data-oauth2-session-items`). */
47
+ list?: string;
48
+ /**
49
+ * Each `<li>` (`data-oauth2-session`, whose value is the session id; the
50
+ * current session also carries `data-oauth2-current-session`).
51
+ */
52
+ item?: string;
53
+ /** The device text of each session (`data-oauth2-session-device`). */
54
+ device?: string;
55
+ /** The current-session badge (`data-oauth2-session-badge`). */
56
+ badge?: string;
57
+ /** The IP and time line under the device (`data-oauth2-session-meta`). */
58
+ meta?: string;
59
+ /** Each per-session "Sign out" button (`data-oauth2-revoke-session`). */
60
+ revoke?: string;
61
+ /** The wrapper of the "Sign out everywhere else" form (`data-oauth2-actions`). */
62
+ actions?: string;
63
+ /**
64
+ * The "Sign out everywhere else" button
65
+ * (`data-oauth2-revoke-other-sessions`).
66
+ */
67
+ revokeOthers?: string;
68
+ /** The error summary shown after a failed action (`data-oauth2-error-summary`). */
69
+ errorSummary?: string;
70
+ /** The text shown when there are no sessions (`data-oauth2-empty`). */
71
+ empty?: string;
72
+ }
73
+ /** Visible text overrides for {@link SessionList}. */
74
+ export interface SessionListLabels {
75
+ /** Badge on the current session. Default: `"Current session"`. */
76
+ current?: string;
77
+ /** Device text when a session has none. Default: `"Unknown device"`. */
78
+ unknownDevice?: string;
79
+ /** Prefix of the sign-in time. Default: `"Signed in"`. */
80
+ signedIn?: string;
81
+ /** Prefix of the last-used time. Default: `"Last active"`. */
82
+ lastActive?: string;
83
+ /**
84
+ * Per-session button text. Default: `"Sign out"`. Its accessible name adds
85
+ * the session's device, such as "Sign out Firefox on Linux".
86
+ */
87
+ revoke?: string;
88
+ /** Per-session button text while pending. Default: `"Signing out…"`. */
89
+ revoking?: string;
90
+ /** Text of the button for every other session. Default: `"Sign out everywhere else"`. */
91
+ revokeOthers?: string;
92
+ /** That button's text while pending. Default: `"Signing out…"`. */
93
+ revokingOthers?: string;
94
+ /** Shown when `sessions` is empty. Default: `"No active sessions."`. */
95
+ empty?: string;
96
+ }
97
+ /**
98
+ * The live state {@link SessionList} hands to a render-prop `children`: the
99
+ * sessions, which action is pending, the last error, and the two actions with
100
+ * the component's single-flight guard applied.
101
+ */
102
+ export interface SessionListState {
103
+ /** The sessions passed to the component. */
104
+ sessions: readonly SessionListItem[];
105
+ /** The id of the session whose sign-out is pending, else `null`. */
106
+ pendingSessionId: string | null;
107
+ /** `true` while "Sign out everywhere else" is pending. */
108
+ revokingOthers: boolean;
109
+ /** The message from the last failed action, else `null`. */
110
+ error: string | null;
111
+ /**
112
+ * Runs `onRevoke` for a session. Ignored while any action is pending or
113
+ * when `onRevoke` was not passed.
114
+ */
115
+ revoke(session: SessionListItem): Promise<void>;
116
+ /**
117
+ * Runs `onRevokeOthers`. Ignored while any action is pending or when
118
+ * `onRevokeOthers` was not passed.
119
+ */
120
+ revokeOthers(): Promise<void>;
121
+ }
122
+ /** Props for {@link SessionList}. */
123
+ export interface SessionListProps {
124
+ /** The account's live sessions, in the order to list them. */
125
+ sessions: readonly SessionListItem[];
126
+ /**
127
+ * Signs out one session other than the current one. Omit it, with
128
+ * `onRevokeOthers`, for a read-only list — for example while an
129
+ * administrator views someone else's account.
130
+ */
131
+ onRevoke?: AccountActionHandler<SessionListItem>;
132
+ /**
133
+ * Signs out every session except the current one. The button shows only
134
+ * when this is passed and at least one other session is listed.
135
+ */
136
+ onRevokeOthers?: () => Promise<AccountActionResult | void> | AccountActionResult | void;
137
+ /**
138
+ * Formats `createdAt` and `lastActiveAt`. Defaults to the runtime's locale
139
+ * and time zone, which can differ between server and browser; pass a
140
+ * formatter with a fixed locale and `timeZone` on a server-rendered page so
141
+ * hydration matches.
142
+ */
143
+ formatDate?: (date: Date) => string;
144
+ /**
145
+ * `action` for each button's `<form>`. Set it on a server-rendered page so
146
+ * the buttons still post when JavaScript never arrives: a session's
147
+ * "Sign out" posts `intent=revoke-session` and `sessionId`, and "Sign out
148
+ * everywhere else" posts `intent=revoke-other-sessions`. Once React is
149
+ * running, the callbacks handle the submit and the native post is
150
+ * suppressed. The forms always use `post`. A native post cannot carry a
151
+ * CSRF header, so check `Origin` or `Sec-Fetch-Site` on the route that
152
+ * receives it.
153
+ */
154
+ action?: string;
155
+ /** Class for the root wrapper (merged with `classNames.root`). */
156
+ className?: string;
157
+ /** Per-slot class hooks for theming. See {@link SessionListClassNames}. */
158
+ classNames?: SessionListClassNames;
159
+ /** Text overrides. */
160
+ labels?: SessionListLabels;
161
+ /**
162
+ * Render-prop escape hatch. When provided, you own the markup and receive
163
+ * the live {@link SessionListState}; the component still owns the pending
164
+ * and error state.
165
+ */
166
+ children?: (state: SessionListState) => ReactNode;
167
+ }
168
+ /**
169
+ * A ready-to-use list of an account's signed-in sessions. Pass the sessions
170
+ * your loader read and wire `onRevoke` / `onRevokeOthers` to your server;
171
+ * after an action succeeds, pass the updated `sessions` so the list follows.
172
+ *
173
+ * Each session shows its device, the current-session badge, its IP address
174
+ * and its sign-in and last-active times. A failed action shows its message in
175
+ * an error summary that takes focus, and a pending button keeps focus with
176
+ * `aria-disabled="true"`.
177
+ *
178
+ * @example
179
+ * ```tsx
180
+ * import {
181
+ * SessionList,
182
+ * type SessionListItem,
183
+ * } from "@udibo/oauth2/react/components";
184
+ *
185
+ * function Sessions(props: { sessions: SessionListItem[] }) {
186
+ * return (
187
+ * <SessionList
188
+ * sessions={props.sessions}
189
+ * onRevoke={async (session) => {
190
+ * const response = await fetch(`/account/sessions/${session.id}`, {
191
+ * method: "DELETE",
192
+ * });
193
+ * if (!response.ok) return { error: "Couldn't sign out that session." };
194
+ * }}
195
+ * onRevokeOthers={async () => {
196
+ * const response = await fetch("/account/sessions", { method: "DELETE" });
197
+ * if (!response.ok) return { error: "Couldn't sign out other sessions." };
198
+ * }}
199
+ * />
200
+ * );
201
+ * }
202
+ * ```
203
+ */
204
+ export declare function SessionList(props: SessionListProps): ReactNode;