bwh-auth 0.6.5 → 0.7.0

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/dist/index.d.cts CHANGED
@@ -54,6 +54,8 @@ export interface AuthJsonResponse {
54
54
  attempt_token?: string;
55
55
  [key: string]: unknown;
56
56
  }
57
+ /** HTTP methods the JSON auth forms may send. */
58
+ export type AuthFormMethod = 'POST' | 'PUT' | 'PATCH';
57
59
  export type AuthButtonVariant = 'default' | 'destructive' | 'outline' | 'secondary' | 'ghost' | 'link';
58
60
  export type AuthButtonSize = 'default' | 'sm' | 'lg' | 'icon' | 'icon-sm' | 'icon-lg';
59
61
  export type AuthButtonComponentProps = React.ButtonHTMLAttributes<HTMLButtonElement> & {
@@ -107,6 +109,72 @@ export type AuthButtonComponent = AuthComponentSet['Button'];
107
109
  export type AuthComponentSuperset = AuthComponentSet & Record<string, React.ComponentType<any>>;
108
110
  export type AuthComponentInput = AuthComponentSet | AuthComponentSuperset;
109
111
  export type AuthButtonComponentInput = Pick<AuthComponentSet, 'Button'> & Record<string, React.ComponentType<any>>;
112
+ /** Overridable copy shared by `EmailCodeForm` and `TwoFactorForm`. */
113
+ export interface EmailCodeFormCopy {
114
+ title?: React.ReactNode;
115
+ /** Defaults to "Enter the N-digit code sent to your email address." */
116
+ description?: React.ReactNode;
117
+ codeLabel?: React.ReactNode;
118
+ submitLabel?: React.ReactNode;
119
+ submittingLabel?: React.ReactNode;
120
+ resendLabel?: React.ReactNode;
121
+ resendingLabel?: React.ReactNode;
122
+ /** Shown after a resend when the server's response carries no `message`. */
123
+ resentMessage?: string;
124
+ }
125
+ /** What the `actions` render function receives, for app-specific actions below the form. */
126
+ export interface EmailCodeFormActions {
127
+ /** Replace the status line shown below the actions. */
128
+ setMessage: (message: string) => void;
129
+ /** True while the code or a resend request is in flight. */
130
+ busy: boolean;
131
+ }
132
+ export interface EmailCodeFormProps extends EmailCodeFormCopy {
133
+ components: AuthComponentInput;
134
+ /** Where the code is sent. */
135
+ submitUrl: string;
136
+ /** Builds the request body from the trimmed code. Defaults to `{ code }`. */
137
+ buildSubmitBody?: (code: string) => Record<string, unknown>;
138
+ /** HTTP method for the code request. Defaults to `POST`. */
139
+ method?: AuthFormMethod;
140
+ /** Where "Send a new code" posts. The resend button is hidden when omitted. */
141
+ resendUrl?: string | null;
142
+ /** Builds the resend request body. Defaults to `{}`. */
143
+ buildResendBody?: () => Record<string, unknown>;
144
+ csrfToken?: string;
145
+ /** Number of digits in the code. Defaults to 6. */
146
+ codeLength?: number;
147
+ /** Prefix for element IDs; the code input is `${idPrefix}-code`. Defaults to `email-code`. */
148
+ idPrefix?: string;
149
+ /** Content above the title, such as a logo or an explanation of why the code is needed. */
150
+ header?: React.ReactNode;
151
+ /** Render only the form and actions, without the card, title and description. */
152
+ unwrapped?: boolean;
153
+ /** Hide the resend button even when `resendUrl` is set. */
154
+ hideResend?: boolean;
155
+ /** A hint shown below the actions, e.g. a fixed test code outside production. Nothing is shown when empty. */
156
+ testCodeHint?: string | null;
157
+ /** App-specific actions rendered after the resend button. */
158
+ actions?: React.ReactNode | ((actions: EmailCodeFormActions) => React.ReactNode);
159
+ /**
160
+ * Formats an HTTP 429 using the `Retry-After` seconds (or `null`). Defaults to a message naming the wait;
161
+ * `null` passes the server's own message through.
162
+ */
163
+ rateLimitMessage?: ((retryAfterSeconds: number | null) => string) | null;
164
+ onSubmitStart?: () => void;
165
+ /** Called with the server's response. Without it, a safe `redirect` in the response is followed. */
166
+ onSuccess?: (result: AuthJsonResponse) => void;
167
+ onError?: (message: string) => void;
168
+ /** Called after a successful resend, e.g. to pick up a rotated token from the response. */
169
+ onResend?: (result: AuthJsonResponse) => void;
170
+ }
171
+ /**
172
+ * A form for a code sent by email: sign-in verification, step-up before a sensitive
173
+ * action, or re-verifying an address. The endpoint and request body are the caller's;
174
+ * this owns the input, the busy state and a synchronous guard so two fast clicks or
175
+ * Enter presses send one request.
176
+ */
177
+ export declare function EmailCodeForm({ components, submitUrl, buildSubmitBody, method, resendUrl, buildResendBody, csrfToken, codeLength, idPrefix, header, unwrapped, hideResend, testCodeHint, actions, rateLimitMessage, onSubmitStart, onSuccess, onError, onResend, title, description, codeLabel, submitLabel, submittingLabel, resendLabel, resendingLabel, resentMessage }: EmailCodeFormProps): React.JSX.Element;
110
178
  interface AuthFormProps {
111
179
  endpoints?: AuthEndpointConfig;
112
180
  components: AuthComponentInput;
@@ -148,11 +216,21 @@ interface SignupFormProps extends Omit<AuthFormProps, 'onSuccess'> {
148
216
  submittingLabel?: React.ReactNode;
149
217
  onSuccess?: (result: AuthJsonResponse, values: AuthSignupValues) => void | Promise<void>;
150
218
  }
151
- export interface PasswordResetRequestFormProps extends AuthFormProps {
219
+ interface PasswordFormBaseProps extends AuthFormProps {
152
220
  onSubmitStart?: () => void;
153
221
  submitClassName?: string;
154
222
  }
155
- export interface ResetPasswordFormProps extends PasswordResetRequestFormProps {
223
+ export interface PasswordResetRequestFormProps extends PasswordFormBaseProps {
224
+ /**
225
+ * Called instead of navigating when the response carries a `redirect` URL, e.g. when
226
+ * recovery happens at an identity provider. Without it, the browser goes to that URL.
227
+ * Only http(s) URLs (or URLs relative to the page) are followed or passed here.
228
+ */
229
+ onRedirect?: (url: string, result: AuthJsonResponse) => void;
230
+ /** Formats an HTTP 429 using the `Retry-After` seconds (or `null`). `null` passes the server's own message through. */
231
+ rateLimitMessage?: ((retryAfterSeconds: number | null) => string) | null;
232
+ }
233
+ export interface ResetPasswordFormProps extends PasswordFormBaseProps {
156
234
  token?: string;
157
235
  email?: string;
158
236
  /** Override field IDs when the embedding page already uses the default ID. */
@@ -163,17 +241,42 @@ export interface ResetPasswordFormProps extends PasswordResetRequestFormProps {
163
241
  passwordConfirmationLabel?: React.ReactNode;
164
242
  passwordHelpText?: React.ReactNode;
165
243
  }
166
- interface TwoFactorFormProps extends AuthFormProps {
244
+ export interface TwoFactorFormProps extends AuthFormProps, EmailCodeFormCopy {
167
245
  attemptToken: string;
246
+ /**
247
+ * @deprecated Pass `testCodeHint` instead. When `testCodeHint` is undefined, any value other
248
+ * than `production` still shows the fixed test-code hint.
249
+ */
168
250
  appEnv?: string;
251
+ /** The hint shown below the actions, e.g. a fixed test code. `null` or `''` shows nothing and overrides `appEnv`. */
252
+ testCodeHint?: string | null;
253
+ /** Content above the title, such as a logo. */
254
+ header?: React.ReactNode;
255
+ /** Hide "Send a new code". */
256
+ hideResend?: boolean;
257
+ /** Hide "This was not me". */
258
+ hideReportSuspicious?: boolean;
259
+ reportSuspiciousLabel?: React.ReactNode;
260
+ /** Shown after a report when the server's response carries no `message`. */
261
+ reportedMessage?: string;
262
+ /**
263
+ * Formats an HTTP 429 using the `Retry-After` seconds (or `null`). By default the server's
264
+ * message is shown unchanged; pass a function (e.g. to match `EmailCodeForm`) to replace it.
265
+ */
266
+ rateLimitMessage?: ((retryAfterSeconds: number | null) => string) | null;
267
+ onSubmitStart?: () => void;
169
268
  onReportSuspicious?: (result: AuthJsonResponse) => void;
170
269
  }
171
270
  export declare function LoginForm({ endpoints, components, onSuccess, onError, initialEmail, onEmailChange, rememberMeCheckbox: RememberMeCheckbox, rememberMeLabel, rememberMeDataTest, onSubmitStart, onTwoFactorRequired, onPasskeySuccess, unwrapped, passkeySeparator, enablePasskeys, enablePasskeyAutofill }: LoginFormProps): React.JSX.Element;
172
271
  export declare function SignupForm({ endpoints, components, onSuccess, onError, fields, initialValues, errors, submitMode, title, description, submitLabel, submittingLabel }: SignupFormProps): React.JSX.Element;
173
- export declare function PasswordResetRequestForm({ endpoints, components, onSuccess, onError, onSubmitStart, submitClassName }: PasswordResetRequestFormProps): React.JSX.Element;
272
+ export declare function PasswordResetRequestForm({ endpoints, components, onSuccess, onError, onSubmitStart, submitClassName, onRedirect, rateLimitMessage }: PasswordResetRequestFormProps): React.JSX.Element;
174
273
  export declare function ResetPasswordForm({ endpoints, components, onSuccess, onError, onSubmitStart, submitClassName, token: initialToken, email: initialEmail, idPrefix, minPasswordLength, validatePasswordConfirmation, passwordLabel, passwordConfirmationLabel, passwordHelpText }: ResetPasswordFormProps): React.JSX.Element;
175
- export declare function ChangePasswordForm({ endpoints, components, onSuccess, onError }: AuthFormProps): React.JSX.Element;
176
- export declare function TwoFactorForm({ endpoints, components, attemptToken, appEnv, onSuccess, onError, onReportSuspicious }: TwoFactorFormProps): React.JSX.Element;
274
+ export interface ChangePasswordFormProps extends AuthFormProps {
275
+ /** HTTP method for the change request. Defaults to `POST`. */
276
+ method?: AuthFormMethod;
277
+ }
278
+ export declare function ChangePasswordForm({ endpoints, components, onSuccess, onError, method }: ChangePasswordFormProps): React.JSX.Element;
279
+ export declare function TwoFactorForm({ endpoints, components, attemptToken, appEnv, testCodeHint, header, hideResend, hideReportSuspicious, reportSuspiciousLabel, reportedMessage, rateLimitMessage, onSubmitStart, onSuccess, onError, onReportSuspicious, title, ...copy }: TwoFactorFormProps): React.JSX.Element;
177
280
  interface PasskeyLoginButtonProps {
178
281
  endpoints?: AuthEndpointConfig;
179
282
  components: AuthButtonComponentInput;
@@ -429,4 +532,148 @@ export interface ApiCredentialsSectionProps {
429
532
  export declare function ApiCredentialsSection({ indexUrl, components, links, csrfToken, request, onSuccess, onError, layout }: ApiCredentialsSectionProps): React.JSX.Element;
430
533
  /** PT4H → "4 hours", P30D → "30 days", P1Y → "1 year". Unknown shapes are shown as given. */
431
534
  export declare function describeDuration(spec: string): string;
535
+ /**
536
+ * Conditions that commonly break sign-in links and flows.
537
+ *
538
+ * - `automated`: an automated or headless browser, as used by email security scanners and
539
+ * link previews that open a link before the person does.
540
+ * - `framed`: the page is inside a frame, e.g. an email client's preview pane.
541
+ * - `in-app-browser`: an embedded webview inside another app, which keeps its own cookies
542
+ * and often cannot complete passkey or redirect-based sign-in.
543
+ * - `cookies-disabled`: cookies cannot be set or read, so no session can be kept.
544
+ * - `storage-unavailable`: site storage is blocked (a restricted or read-only context).
545
+ */
546
+ export type AuthBrowserIssueKind = 'automated' | 'framed' | 'in-app-browser' | 'cookies-disabled' | 'storage-unavailable';
547
+ export interface AuthBrowserIssue {
548
+ kind: AuthBrowserIssueKind;
549
+ /** For `in-app-browser`: the host app, when recognised from the user agent. */
550
+ app?: string;
551
+ }
552
+ /** What detection reads. Every field is optional; a missing one is treated as "no problem". */
553
+ export interface AuthBrowserEnvironment {
554
+ userAgent?: string;
555
+ /** `navigator.webdriver`. */
556
+ webdriver?: boolean;
557
+ /** The page is not the top-level browsing context. */
558
+ framed?: boolean;
559
+ /** `navigator.cookieEnabled`. */
560
+ cookieEnabled?: boolean;
561
+ /** A short-lived test cookie could be written and read back. */
562
+ cookiesWritable?: boolean;
563
+ /** `localStorage` could be written. */
564
+ storageAvailable?: boolean;
565
+ /** Running as an installed home-screen web app, whose iOS user agent also lacks a "Safari/" token. */
566
+ standalone?: boolean;
567
+ }
568
+ /** Read the current browser's environment. Returns `{}` during server rendering. */
569
+ export declare function readAuthBrowserEnvironment(): AuthBrowserEnvironment;
570
+ /** Name the conditions in `environment` that are likely to break sign-in, most fundamental first. */
571
+ export declare function detectAuthBrowserIssues(environment?: AuthBrowserEnvironment): AuthBrowserIssue[];
572
+ export interface AuthBrowserHelpCopy {
573
+ title?: React.ReactNode;
574
+ body?: React.ReactNode;
575
+ }
576
+ /** Only `Button` is required; an `Alert` is used when given, otherwise a `<div role="status">`. */
577
+ export type AuthBrowserHelpComponents = Pick<AuthComponentSet, 'Button'> & Partial<Pick<AuthComponentSet, 'Alert'>>;
578
+ export interface AuthBrowserHelpProps {
579
+ components: AuthBrowserHelpComponents;
580
+ /** Show these instead of detecting, e.g. from a server-side user-agent check. */
581
+ issues?: AuthBrowserIssue[];
582
+ /** Detect from this environment instead of the live browser. */
583
+ environment?: AuthBrowserEnvironment;
584
+ /** Kinds never to show. */
585
+ ignore?: AuthBrowserIssueKind[];
586
+ /** Replace the title and/or body for a kind. */
587
+ messages?: Partial<Record<AuthBrowserIssueKind, AuthBrowserHelpCopy>>;
588
+ /** The address offered by "Copy link" and "Open in a new tab". Defaults to the current page. */
589
+ url?: string;
590
+ className?: string;
591
+ /** Called once detection has run (also with an empty list), e.g. to hold back an auto-submit. */
592
+ onDetect?: (issues: AuthBrowserIssue[]) => void;
593
+ }
594
+ /**
595
+ * Guidance for browsers and contexts that commonly break sign-in links and flows.
596
+ *
597
+ * Detection runs after mount, so server rendering and the first client render show
598
+ * nothing and hydrate identically. Nothing renders when no issue applies.
599
+ */
600
+ export declare function AuthBrowserHelp({ components, issues: givenIssues, environment, ignore, messages, url, className, onDetect }: AuthBrowserHelpProps): React.JSX.Element | null;
601
+ /** Events auth-laravel's audit logger records (`BWH\Auth\Models\AuthAuditLog::EVENT_*`). */
602
+ export type AuthAuditEvent = 'login_succeeded' | 'login_failed' | 'login_blocked' | 'logged_out' | 'two_factor_challenge_created' | 'two_factor_succeeded' | 'two_factor_failed' | 'two_factor_reported_suspicious' | 'passkey_registered' | 'passkey_deleted' | 'passkey_login_succeeded' | 'passkey_login_failed' | 'password_reset_requested' | 'password_reset_completed' | 'password_changed';
603
+ /** One row of `GET /api/auth/audit-log`: an `auth_audit_log` record as the server serialises it. */
604
+ export interface AuthAuditLogEntry {
605
+ id: number;
606
+ user_id: number | null;
607
+ acting_user_id: number | null;
608
+ email: string | null;
609
+ /** A known `AuthAuditEvent`, or an event an application records itself. */
610
+ event: AuthAuditEvent | (string & {});
611
+ /** `password`, `passkey`, `two_factor`, another method an application records, or `null`. */
612
+ auth_method: string | null;
613
+ succeeded: boolean;
614
+ reason: string | null;
615
+ /** Text form (IPv4 or IPv6); the server stores it as binary and converts it back. */
616
+ ip_address: string | null;
617
+ user_agent: string | null;
618
+ session_id: string | null;
619
+ is_suspicious: boolean;
620
+ metadata: Record<string, unknown> | null;
621
+ /** ISO-8601 timestamps. */
622
+ created_at: string | null;
623
+ updated_at: string | null;
624
+ /** Not sent by auth-laravel; shown when an application adds a location to each row. */
625
+ location?: string | null;
626
+ }
627
+ /** The Laravel length-aware paginator body the endpoint returns. */
628
+ export interface AuthAuditLogPage {
629
+ current_page: number;
630
+ data: AuthAuditLogEntry[];
631
+ last_page: number;
632
+ per_page: number;
633
+ total: number;
634
+ from: number | null;
635
+ to: number | null;
636
+ next_page_url: string | null;
637
+ prev_page_url: string | null;
638
+ }
639
+ /** The events `SignInHistory` shows by default: sign-in attempts and their second factor. */
640
+ export declare const SIGN_IN_AUDIT_EVENTS: readonly AuthAuditEvent[];
641
+ /**
642
+ * Validate an audit-log response into a page that is safe to render, or `null` if it is not one.
643
+ * Malformed rows are dropped rather than failing the whole page.
644
+ */
645
+ export declare function parseAuthAuditLogPage(payload: unknown): AuthAuditLogPage | null;
646
+ /**
647
+ * Performs one GET in place of the built-in `fetch`, e.g. through the app's own HTTP client.
648
+ * Resolve with the parsed paginator body as `payload`, or with `{ ok: false, status, message }`.
649
+ */
650
+ export type SignInHistoryRequest = (url: string) => Promise<ApiCredentialRequestResult>;
651
+ /** Only `Button` is required. `Alert` (errors) and `Badge` (result and flag labels) fall back to native elements. */
652
+ export type SignInHistoryComponents = Pick<AuthComponentSet, 'Button'> & Partial<Pick<AuthComponentSet, 'Alert' | 'Badge'>>;
653
+ export interface SignInHistoryProps {
654
+ components: SignInHistoryComponents;
655
+ /** The audit-log endpoint. Defaults to auth-laravel's `/api/auth/audit-log`. */
656
+ url?: string;
657
+ /** Rows per request, 1 to 100 (the server's limit). Defaults to 20. */
658
+ perPage?: number;
659
+ /** Events to show. Defaults to `SIGN_IN_AUDIT_EVENTS`; `'all'` shows every recorded event. */
660
+ events?: readonly string[] | 'all';
661
+ /** Replaces the built-in `fetch`. */
662
+ request?: SignInHistoryRequest;
663
+ /** Formats `created_at`. Defaults to the browser's locale date and time. */
664
+ formatTime?: (iso: string) => string;
665
+ eventLabels?: Partial<Record<string, React.ReactNode>>;
666
+ methodLabels?: Partial<Record<string, React.ReactNode>>;
667
+ emptyMessage?: React.ReactNode;
668
+ /** Accessible name for the table. */
669
+ label?: string;
670
+ className?: string;
671
+ onError?: (message: string) => void;
672
+ }
673
+ /**
674
+ * The signed-in person's recent sign-in activity, read from auth-laravel's audit-log
675
+ * endpoint (`GET /api/auth/audit-log`, enabled by `bherila-auth.audit.routes_enabled`,
676
+ * session-authenticated). Newest first, with "Load more" for older pages.
677
+ */
678
+ export declare function SignInHistory({ components, url, perPage, events, request, formatTime, eventLabels, methodLabels, emptyMessage, label, className, onError }: SignInHistoryProps): React.JSX.Element;
432
679
  export {};
package/dist/index.d.ts CHANGED
@@ -54,6 +54,8 @@ export interface AuthJsonResponse {
54
54
  attempt_token?: string;
55
55
  [key: string]: unknown;
56
56
  }
57
+ /** HTTP methods the JSON auth forms may send. */
58
+ export type AuthFormMethod = 'POST' | 'PUT' | 'PATCH';
57
59
  export type AuthButtonVariant = 'default' | 'destructive' | 'outline' | 'secondary' | 'ghost' | 'link';
58
60
  export type AuthButtonSize = 'default' | 'sm' | 'lg' | 'icon' | 'icon-sm' | 'icon-lg';
59
61
  export type AuthButtonComponentProps = React.ButtonHTMLAttributes<HTMLButtonElement> & {
@@ -107,6 +109,72 @@ export type AuthButtonComponent = AuthComponentSet['Button'];
107
109
  export type AuthComponentSuperset = AuthComponentSet & Record<string, React.ComponentType<any>>;
108
110
  export type AuthComponentInput = AuthComponentSet | AuthComponentSuperset;
109
111
  export type AuthButtonComponentInput = Pick<AuthComponentSet, 'Button'> & Record<string, React.ComponentType<any>>;
112
+ /** Overridable copy shared by `EmailCodeForm` and `TwoFactorForm`. */
113
+ export interface EmailCodeFormCopy {
114
+ title?: React.ReactNode;
115
+ /** Defaults to "Enter the N-digit code sent to your email address." */
116
+ description?: React.ReactNode;
117
+ codeLabel?: React.ReactNode;
118
+ submitLabel?: React.ReactNode;
119
+ submittingLabel?: React.ReactNode;
120
+ resendLabel?: React.ReactNode;
121
+ resendingLabel?: React.ReactNode;
122
+ /** Shown after a resend when the server's response carries no `message`. */
123
+ resentMessage?: string;
124
+ }
125
+ /** What the `actions` render function receives, for app-specific actions below the form. */
126
+ export interface EmailCodeFormActions {
127
+ /** Replace the status line shown below the actions. */
128
+ setMessage: (message: string) => void;
129
+ /** True while the code or a resend request is in flight. */
130
+ busy: boolean;
131
+ }
132
+ export interface EmailCodeFormProps extends EmailCodeFormCopy {
133
+ components: AuthComponentInput;
134
+ /** Where the code is sent. */
135
+ submitUrl: string;
136
+ /** Builds the request body from the trimmed code. Defaults to `{ code }`. */
137
+ buildSubmitBody?: (code: string) => Record<string, unknown>;
138
+ /** HTTP method for the code request. Defaults to `POST`. */
139
+ method?: AuthFormMethod;
140
+ /** Where "Send a new code" posts. The resend button is hidden when omitted. */
141
+ resendUrl?: string | null;
142
+ /** Builds the resend request body. Defaults to `{}`. */
143
+ buildResendBody?: () => Record<string, unknown>;
144
+ csrfToken?: string;
145
+ /** Number of digits in the code. Defaults to 6. */
146
+ codeLength?: number;
147
+ /** Prefix for element IDs; the code input is `${idPrefix}-code`. Defaults to `email-code`. */
148
+ idPrefix?: string;
149
+ /** Content above the title, such as a logo or an explanation of why the code is needed. */
150
+ header?: React.ReactNode;
151
+ /** Render only the form and actions, without the card, title and description. */
152
+ unwrapped?: boolean;
153
+ /** Hide the resend button even when `resendUrl` is set. */
154
+ hideResend?: boolean;
155
+ /** A hint shown below the actions, e.g. a fixed test code outside production. Nothing is shown when empty. */
156
+ testCodeHint?: string | null;
157
+ /** App-specific actions rendered after the resend button. */
158
+ actions?: React.ReactNode | ((actions: EmailCodeFormActions) => React.ReactNode);
159
+ /**
160
+ * Formats an HTTP 429 using the `Retry-After` seconds (or `null`). Defaults to a message naming the wait;
161
+ * `null` passes the server's own message through.
162
+ */
163
+ rateLimitMessage?: ((retryAfterSeconds: number | null) => string) | null;
164
+ onSubmitStart?: () => void;
165
+ /** Called with the server's response. Without it, a safe `redirect` in the response is followed. */
166
+ onSuccess?: (result: AuthJsonResponse) => void;
167
+ onError?: (message: string) => void;
168
+ /** Called after a successful resend, e.g. to pick up a rotated token from the response. */
169
+ onResend?: (result: AuthJsonResponse) => void;
170
+ }
171
+ /**
172
+ * A form for a code sent by email: sign-in verification, step-up before a sensitive
173
+ * action, or re-verifying an address. The endpoint and request body are the caller's;
174
+ * this owns the input, the busy state and a synchronous guard so two fast clicks or
175
+ * Enter presses send one request.
176
+ */
177
+ export declare function EmailCodeForm({ components, submitUrl, buildSubmitBody, method, resendUrl, buildResendBody, csrfToken, codeLength, idPrefix, header, unwrapped, hideResend, testCodeHint, actions, rateLimitMessage, onSubmitStart, onSuccess, onError, onResend, title, description, codeLabel, submitLabel, submittingLabel, resendLabel, resendingLabel, resentMessage }: EmailCodeFormProps): React.JSX.Element;
110
178
  interface AuthFormProps {
111
179
  endpoints?: AuthEndpointConfig;
112
180
  components: AuthComponentInput;
@@ -148,11 +216,21 @@ interface SignupFormProps extends Omit<AuthFormProps, 'onSuccess'> {
148
216
  submittingLabel?: React.ReactNode;
149
217
  onSuccess?: (result: AuthJsonResponse, values: AuthSignupValues) => void | Promise<void>;
150
218
  }
151
- export interface PasswordResetRequestFormProps extends AuthFormProps {
219
+ interface PasswordFormBaseProps extends AuthFormProps {
152
220
  onSubmitStart?: () => void;
153
221
  submitClassName?: string;
154
222
  }
155
- export interface ResetPasswordFormProps extends PasswordResetRequestFormProps {
223
+ export interface PasswordResetRequestFormProps extends PasswordFormBaseProps {
224
+ /**
225
+ * Called instead of navigating when the response carries a `redirect` URL, e.g. when
226
+ * recovery happens at an identity provider. Without it, the browser goes to that URL.
227
+ * Only http(s) URLs (or URLs relative to the page) are followed or passed here.
228
+ */
229
+ onRedirect?: (url: string, result: AuthJsonResponse) => void;
230
+ /** Formats an HTTP 429 using the `Retry-After` seconds (or `null`). `null` passes the server's own message through. */
231
+ rateLimitMessage?: ((retryAfterSeconds: number | null) => string) | null;
232
+ }
233
+ export interface ResetPasswordFormProps extends PasswordFormBaseProps {
156
234
  token?: string;
157
235
  email?: string;
158
236
  /** Override field IDs when the embedding page already uses the default ID. */
@@ -163,17 +241,42 @@ export interface ResetPasswordFormProps extends PasswordResetRequestFormProps {
163
241
  passwordConfirmationLabel?: React.ReactNode;
164
242
  passwordHelpText?: React.ReactNode;
165
243
  }
166
- interface TwoFactorFormProps extends AuthFormProps {
244
+ export interface TwoFactorFormProps extends AuthFormProps, EmailCodeFormCopy {
167
245
  attemptToken: string;
246
+ /**
247
+ * @deprecated Pass `testCodeHint` instead. When `testCodeHint` is undefined, any value other
248
+ * than `production` still shows the fixed test-code hint.
249
+ */
168
250
  appEnv?: string;
251
+ /** The hint shown below the actions, e.g. a fixed test code. `null` or `''` shows nothing and overrides `appEnv`. */
252
+ testCodeHint?: string | null;
253
+ /** Content above the title, such as a logo. */
254
+ header?: React.ReactNode;
255
+ /** Hide "Send a new code". */
256
+ hideResend?: boolean;
257
+ /** Hide "This was not me". */
258
+ hideReportSuspicious?: boolean;
259
+ reportSuspiciousLabel?: React.ReactNode;
260
+ /** Shown after a report when the server's response carries no `message`. */
261
+ reportedMessage?: string;
262
+ /**
263
+ * Formats an HTTP 429 using the `Retry-After` seconds (or `null`). By default the server's
264
+ * message is shown unchanged; pass a function (e.g. to match `EmailCodeForm`) to replace it.
265
+ */
266
+ rateLimitMessage?: ((retryAfterSeconds: number | null) => string) | null;
267
+ onSubmitStart?: () => void;
169
268
  onReportSuspicious?: (result: AuthJsonResponse) => void;
170
269
  }
171
270
  export declare function LoginForm({ endpoints, components, onSuccess, onError, initialEmail, onEmailChange, rememberMeCheckbox: RememberMeCheckbox, rememberMeLabel, rememberMeDataTest, onSubmitStart, onTwoFactorRequired, onPasskeySuccess, unwrapped, passkeySeparator, enablePasskeys, enablePasskeyAutofill }: LoginFormProps): React.JSX.Element;
172
271
  export declare function SignupForm({ endpoints, components, onSuccess, onError, fields, initialValues, errors, submitMode, title, description, submitLabel, submittingLabel }: SignupFormProps): React.JSX.Element;
173
- export declare function PasswordResetRequestForm({ endpoints, components, onSuccess, onError, onSubmitStart, submitClassName }: PasswordResetRequestFormProps): React.JSX.Element;
272
+ export declare function PasswordResetRequestForm({ endpoints, components, onSuccess, onError, onSubmitStart, submitClassName, onRedirect, rateLimitMessage }: PasswordResetRequestFormProps): React.JSX.Element;
174
273
  export declare function ResetPasswordForm({ endpoints, components, onSuccess, onError, onSubmitStart, submitClassName, token: initialToken, email: initialEmail, idPrefix, minPasswordLength, validatePasswordConfirmation, passwordLabel, passwordConfirmationLabel, passwordHelpText }: ResetPasswordFormProps): React.JSX.Element;
175
- export declare function ChangePasswordForm({ endpoints, components, onSuccess, onError }: AuthFormProps): React.JSX.Element;
176
- export declare function TwoFactorForm({ endpoints, components, attemptToken, appEnv, onSuccess, onError, onReportSuspicious }: TwoFactorFormProps): React.JSX.Element;
274
+ export interface ChangePasswordFormProps extends AuthFormProps {
275
+ /** HTTP method for the change request. Defaults to `POST`. */
276
+ method?: AuthFormMethod;
277
+ }
278
+ export declare function ChangePasswordForm({ endpoints, components, onSuccess, onError, method }: ChangePasswordFormProps): React.JSX.Element;
279
+ export declare function TwoFactorForm({ endpoints, components, attemptToken, appEnv, testCodeHint, header, hideResend, hideReportSuspicious, reportSuspiciousLabel, reportedMessage, rateLimitMessage, onSubmitStart, onSuccess, onError, onReportSuspicious, title, ...copy }: TwoFactorFormProps): React.JSX.Element;
177
280
  interface PasskeyLoginButtonProps {
178
281
  endpoints?: AuthEndpointConfig;
179
282
  components: AuthButtonComponentInput;
@@ -429,4 +532,148 @@ export interface ApiCredentialsSectionProps {
429
532
  export declare function ApiCredentialsSection({ indexUrl, components, links, csrfToken, request, onSuccess, onError, layout }: ApiCredentialsSectionProps): React.JSX.Element;
430
533
  /** PT4H → "4 hours", P30D → "30 days", P1Y → "1 year". Unknown shapes are shown as given. */
431
534
  export declare function describeDuration(spec: string): string;
535
+ /**
536
+ * Conditions that commonly break sign-in links and flows.
537
+ *
538
+ * - `automated`: an automated or headless browser, as used by email security scanners and
539
+ * link previews that open a link before the person does.
540
+ * - `framed`: the page is inside a frame, e.g. an email client's preview pane.
541
+ * - `in-app-browser`: an embedded webview inside another app, which keeps its own cookies
542
+ * and often cannot complete passkey or redirect-based sign-in.
543
+ * - `cookies-disabled`: cookies cannot be set or read, so no session can be kept.
544
+ * - `storage-unavailable`: site storage is blocked (a restricted or read-only context).
545
+ */
546
+ export type AuthBrowserIssueKind = 'automated' | 'framed' | 'in-app-browser' | 'cookies-disabled' | 'storage-unavailable';
547
+ export interface AuthBrowserIssue {
548
+ kind: AuthBrowserIssueKind;
549
+ /** For `in-app-browser`: the host app, when recognised from the user agent. */
550
+ app?: string;
551
+ }
552
+ /** What detection reads. Every field is optional; a missing one is treated as "no problem". */
553
+ export interface AuthBrowserEnvironment {
554
+ userAgent?: string;
555
+ /** `navigator.webdriver`. */
556
+ webdriver?: boolean;
557
+ /** The page is not the top-level browsing context. */
558
+ framed?: boolean;
559
+ /** `navigator.cookieEnabled`. */
560
+ cookieEnabled?: boolean;
561
+ /** A short-lived test cookie could be written and read back. */
562
+ cookiesWritable?: boolean;
563
+ /** `localStorage` could be written. */
564
+ storageAvailable?: boolean;
565
+ /** Running as an installed home-screen web app, whose iOS user agent also lacks a "Safari/" token. */
566
+ standalone?: boolean;
567
+ }
568
+ /** Read the current browser's environment. Returns `{}` during server rendering. */
569
+ export declare function readAuthBrowserEnvironment(): AuthBrowserEnvironment;
570
+ /** Name the conditions in `environment` that are likely to break sign-in, most fundamental first. */
571
+ export declare function detectAuthBrowserIssues(environment?: AuthBrowserEnvironment): AuthBrowserIssue[];
572
+ export interface AuthBrowserHelpCopy {
573
+ title?: React.ReactNode;
574
+ body?: React.ReactNode;
575
+ }
576
+ /** Only `Button` is required; an `Alert` is used when given, otherwise a `<div role="status">`. */
577
+ export type AuthBrowserHelpComponents = Pick<AuthComponentSet, 'Button'> & Partial<Pick<AuthComponentSet, 'Alert'>>;
578
+ export interface AuthBrowserHelpProps {
579
+ components: AuthBrowserHelpComponents;
580
+ /** Show these instead of detecting, e.g. from a server-side user-agent check. */
581
+ issues?: AuthBrowserIssue[];
582
+ /** Detect from this environment instead of the live browser. */
583
+ environment?: AuthBrowserEnvironment;
584
+ /** Kinds never to show. */
585
+ ignore?: AuthBrowserIssueKind[];
586
+ /** Replace the title and/or body for a kind. */
587
+ messages?: Partial<Record<AuthBrowserIssueKind, AuthBrowserHelpCopy>>;
588
+ /** The address offered by "Copy link" and "Open in a new tab". Defaults to the current page. */
589
+ url?: string;
590
+ className?: string;
591
+ /** Called once detection has run (also with an empty list), e.g. to hold back an auto-submit. */
592
+ onDetect?: (issues: AuthBrowserIssue[]) => void;
593
+ }
594
+ /**
595
+ * Guidance for browsers and contexts that commonly break sign-in links and flows.
596
+ *
597
+ * Detection runs after mount, so server rendering and the first client render show
598
+ * nothing and hydrate identically. Nothing renders when no issue applies.
599
+ */
600
+ export declare function AuthBrowserHelp({ components, issues: givenIssues, environment, ignore, messages, url, className, onDetect }: AuthBrowserHelpProps): React.JSX.Element | null;
601
+ /** Events auth-laravel's audit logger records (`BWH\Auth\Models\AuthAuditLog::EVENT_*`). */
602
+ export type AuthAuditEvent = 'login_succeeded' | 'login_failed' | 'login_blocked' | 'logged_out' | 'two_factor_challenge_created' | 'two_factor_succeeded' | 'two_factor_failed' | 'two_factor_reported_suspicious' | 'passkey_registered' | 'passkey_deleted' | 'passkey_login_succeeded' | 'passkey_login_failed' | 'password_reset_requested' | 'password_reset_completed' | 'password_changed';
603
+ /** One row of `GET /api/auth/audit-log`: an `auth_audit_log` record as the server serialises it. */
604
+ export interface AuthAuditLogEntry {
605
+ id: number;
606
+ user_id: number | null;
607
+ acting_user_id: number | null;
608
+ email: string | null;
609
+ /** A known `AuthAuditEvent`, or an event an application records itself. */
610
+ event: AuthAuditEvent | (string & {});
611
+ /** `password`, `passkey`, `two_factor`, another method an application records, or `null`. */
612
+ auth_method: string | null;
613
+ succeeded: boolean;
614
+ reason: string | null;
615
+ /** Text form (IPv4 or IPv6); the server stores it as binary and converts it back. */
616
+ ip_address: string | null;
617
+ user_agent: string | null;
618
+ session_id: string | null;
619
+ is_suspicious: boolean;
620
+ metadata: Record<string, unknown> | null;
621
+ /** ISO-8601 timestamps. */
622
+ created_at: string | null;
623
+ updated_at: string | null;
624
+ /** Not sent by auth-laravel; shown when an application adds a location to each row. */
625
+ location?: string | null;
626
+ }
627
+ /** The Laravel length-aware paginator body the endpoint returns. */
628
+ export interface AuthAuditLogPage {
629
+ current_page: number;
630
+ data: AuthAuditLogEntry[];
631
+ last_page: number;
632
+ per_page: number;
633
+ total: number;
634
+ from: number | null;
635
+ to: number | null;
636
+ next_page_url: string | null;
637
+ prev_page_url: string | null;
638
+ }
639
+ /** The events `SignInHistory` shows by default: sign-in attempts and their second factor. */
640
+ export declare const SIGN_IN_AUDIT_EVENTS: readonly AuthAuditEvent[];
641
+ /**
642
+ * Validate an audit-log response into a page that is safe to render, or `null` if it is not one.
643
+ * Malformed rows are dropped rather than failing the whole page.
644
+ */
645
+ export declare function parseAuthAuditLogPage(payload: unknown): AuthAuditLogPage | null;
646
+ /**
647
+ * Performs one GET in place of the built-in `fetch`, e.g. through the app's own HTTP client.
648
+ * Resolve with the parsed paginator body as `payload`, or with `{ ok: false, status, message }`.
649
+ */
650
+ export type SignInHistoryRequest = (url: string) => Promise<ApiCredentialRequestResult>;
651
+ /** Only `Button` is required. `Alert` (errors) and `Badge` (result and flag labels) fall back to native elements. */
652
+ export type SignInHistoryComponents = Pick<AuthComponentSet, 'Button'> & Partial<Pick<AuthComponentSet, 'Alert' | 'Badge'>>;
653
+ export interface SignInHistoryProps {
654
+ components: SignInHistoryComponents;
655
+ /** The audit-log endpoint. Defaults to auth-laravel's `/api/auth/audit-log`. */
656
+ url?: string;
657
+ /** Rows per request, 1 to 100 (the server's limit). Defaults to 20. */
658
+ perPage?: number;
659
+ /** Events to show. Defaults to `SIGN_IN_AUDIT_EVENTS`; `'all'` shows every recorded event. */
660
+ events?: readonly string[] | 'all';
661
+ /** Replaces the built-in `fetch`. */
662
+ request?: SignInHistoryRequest;
663
+ /** Formats `created_at`. Defaults to the browser's locale date and time. */
664
+ formatTime?: (iso: string) => string;
665
+ eventLabels?: Partial<Record<string, React.ReactNode>>;
666
+ methodLabels?: Partial<Record<string, React.ReactNode>>;
667
+ emptyMessage?: React.ReactNode;
668
+ /** Accessible name for the table. */
669
+ label?: string;
670
+ className?: string;
671
+ onError?: (message: string) => void;
672
+ }
673
+ /**
674
+ * The signed-in person's recent sign-in activity, read from auth-laravel's audit-log
675
+ * endpoint (`GET /api/auth/audit-log`, enabled by `bherila-auth.audit.routes_enabled`,
676
+ * session-authenticated). Newest first, with "Load more" for older pages.
677
+ */
678
+ export declare function SignInHistory({ components, url, perPage, events, request, formatTime, eventLabels, methodLabels, emptyMessage, label, className, onError }: SignInHistoryProps): React.JSX.Element;
432
679
  export {};