bwh-auth 0.6.4 → 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/LICENSE +1 -1
- package/README.md +178 -11
- package/dist/index.cjs +3133 -1737
- package/dist/index.d.cts +586 -335
- package/dist/index.d.ts +586 -335
- package/dist/index.js +3079 -1679
- package/package.json +23 -17
package/LICENSE
CHANGED
package/README.md
CHANGED
|
@@ -20,9 +20,20 @@ The companion Laravel API package is
|
|
|
20
20
|
- `ResetPasswordForm`
|
|
21
21
|
- `ChangePasswordForm`
|
|
22
22
|
- `TwoFactorForm`
|
|
23
|
+
- `EmailCodeForm`
|
|
23
24
|
- `PasskeyLoginButton`
|
|
24
25
|
- `PasskeySection`
|
|
25
26
|
- `ApiCredentialsSection`
|
|
27
|
+
- `AuthBrowserHelp`
|
|
28
|
+
- `SignInHistory`
|
|
29
|
+
|
|
30
|
+
Applications that sign people in through the identity provider
|
|
31
|
+
([Auth Manager](https://github.com/bherila/auth-manager), with auth-laravel's relying-party
|
|
32
|
+
sign-in) mount none of `LoginForm`, `SignupForm`, `PasswordResetRequestForm`,
|
|
33
|
+
`ResetPasswordForm`, `TwoFactorForm`, `ChangePasswordForm` or `PasskeySection`. People sign up,
|
|
34
|
+
sign in, reset their password, manage passkeys and redeem invite codes at the provider; the
|
|
35
|
+
provider itself mounts `PasskeySection` and uses the passkey helpers. The credential forms stay
|
|
36
|
+
for an application that keeps credentials of its own.
|
|
26
37
|
|
|
27
38
|
## Relying-party helpers
|
|
28
39
|
|
|
@@ -110,7 +121,7 @@ export function LoginPage() {
|
|
|
110
121
|
|
|
111
122
|
## Custom Signup Fields
|
|
112
123
|
|
|
113
|
-
`SignupForm` is field-driven so
|
|
124
|
+
`SignupForm` is field-driven so an app that runs its own sign-up can keep app-specific registration concepts, such as invite codes or policy checkboxes, while reusing the shared auth form behavior. An app that signs in through the identity provider sends people to the provider's sign-up page instead, and its invite codes are the provider's.
|
|
114
125
|
|
|
115
126
|
```tsx
|
|
116
127
|
<SignupForm
|
|
@@ -122,7 +133,7 @@ export function LoginPage() {
|
|
|
122
133
|
{ name: 'email', label: 'Email', type: 'email', required: true, autoComplete: 'email' },
|
|
123
134
|
{ name: 'password', label: 'Password', type: 'password', required: true, minLength: 8, autoComplete: 'new-password' },
|
|
124
135
|
{ name: 'password_confirmation', label: 'Confirm Password', type: 'password', required: true, minLength: 8, autoComplete: 'new-password' },
|
|
125
|
-
{ name: 'invite_code', label: '
|
|
136
|
+
{ name: 'invite_code', label: 'Invite Code', required: true },
|
|
126
137
|
{ name: 'agreement', label: 'I agree to keep this program confidential.', type: 'checkbox', required: true },
|
|
127
138
|
]}
|
|
128
139
|
/>
|
|
@@ -240,7 +251,8 @@ CSRF overrides remain available through `endpoints`.
|
|
|
240
251
|
|
|
241
252
|
## Password Change
|
|
242
253
|
|
|
243
|
-
`ChangePasswordForm` is intended for authenticated settings pages or dialogs. The consuming app owns the wrapper and backend endpoint; the form posts to `/api/change-password` by default and accepts `endpoints.changePassword` for apps that use a different route.
|
|
254
|
+
`ChangePasswordForm` is intended for authenticated settings pages or dialogs. The consuming app owns the wrapper and backend endpoint; the form posts to `/api/change-password` by default and accepts `endpoints.changePassword` for apps that use a different route. `method` (`'POST'`, `'PUT'` or `'PATCH'`, default `'POST'`) matches
|
|
255
|
+
an app route that expects another verb. Duplicate submissions are ignored while a request is pending.
|
|
244
256
|
|
|
245
257
|
```tsx
|
|
246
258
|
<ChangePasswordForm
|
|
@@ -251,6 +263,131 @@ CSRF overrides remain available through `endpoints`.
|
|
|
251
263
|
/>
|
|
252
264
|
```
|
|
253
265
|
|
|
266
|
+
## Password reset redirects and throttling
|
|
267
|
+
|
|
268
|
+
When the forgot-password response carries a `redirect` URL — for example an application whose
|
|
269
|
+
account recovery happens at an identity provider — `PasswordResetRequestForm` calls `onSuccess` and
|
|
270
|
+
then goes there with `window.location.assign`. Pass `onRedirect(url, result)` to navigate yourself
|
|
271
|
+
instead. Only http(s) URLs, or URLs relative to the page, are followed or passed to `onRedirect`;
|
|
272
|
+
anything else (`javascript:`, `data:`) is ignored. Servers that send no `redirect` behave as before.
|
|
273
|
+
|
|
274
|
+
An HTTP 429 is reported through `onError` as "Too many attempts. Please try again in N seconds."
|
|
275
|
+
using the `Retry-After` header (seconds or an HTTP date), or without a number when there is none.
|
|
276
|
+
`rateLimitMessage={(seconds) => ...}` replaces the wording; `rateLimitMessage={null}` passes the
|
|
277
|
+
server's own message through.
|
|
278
|
+
|
|
279
|
+
## Email codes: `TwoFactorForm` and `EmailCodeForm`
|
|
280
|
+
|
|
281
|
+
`TwoFactorForm` keeps its props, endpoints and request bodies. New optional props:
|
|
282
|
+
|
|
283
|
+
| Prop | Default | Purpose |
|
|
284
|
+
| --- | --- | --- |
|
|
285
|
+
| `header` | none | Content above the title, e.g. a logo. |
|
|
286
|
+
| `title`, `description`, `codeLabel`, `submitLabel`, `submittingLabel`, `resendLabel`, `resendingLabel`, `resentMessage` | current copy | Override the text. |
|
|
287
|
+
| `reportSuspiciousLabel`, `reportedMessage` | current copy | Override the "This was not me" action and its confirmation. |
|
|
288
|
+
| `hideResend`, `hideReportSuspicious` | `false` | Hide "Send a new code" or "This was not me". |
|
|
289
|
+
| `testCodeHint` | derived from `appEnv` | The fixed-test-code hint; `null` or `''` shows nothing. |
|
|
290
|
+
| `rateLimitMessage` | `null` (server message) | Format a 429 from `Retry-After`. |
|
|
291
|
+
| `onSubmitStart` | none | Clear app messages when a code is submitted. |
|
|
292
|
+
|
|
293
|
+
`appEnv` is **deprecated**: it still shows "Dev mode: use 999999 to bypass 2FA." when it is set to
|
|
294
|
+
anything but `production` and `testCodeHint` is undefined. Prefer passing the hint explicitly from
|
|
295
|
+
the server's configuration, so the page never guesses whether a test code is enabled.
|
|
296
|
+
|
|
297
|
+
Submitting is guarded synchronously: two fast clicks or Enter presses send one request, as do
|
|
298
|
+
repeated resend and report clicks. "This was not me" now renders with your injected `Button`
|
|
299
|
+
(`variant="link"`, `size="sm"`) instead of a raw `<button>`.
|
|
300
|
+
|
|
301
|
+
`EmailCodeForm` is the general form `TwoFactorForm` is built on, for any code sent by email: a step-up
|
|
302
|
+
before a sensitive action, re-verifying an address, and so on. It assumes no `attempt_token`; the
|
|
303
|
+
endpoint and bodies are yours.
|
|
304
|
+
|
|
305
|
+
```tsx
|
|
306
|
+
import { EmailCodeForm } from 'bwh-auth';
|
|
307
|
+
|
|
308
|
+
<EmailCodeForm
|
|
309
|
+
components={getShadcnComponents()}
|
|
310
|
+
csrfToken={csrfToken}
|
|
311
|
+
submitUrl="/account/step-up/verify"
|
|
312
|
+
buildSubmitBody={(code) => ({ challenge: challengeId, code })}
|
|
313
|
+
resendUrl="/account/step-up/resend" // omit to hide the resend button
|
|
314
|
+
buildResendBody={() => ({ challenge: challengeId })}
|
|
315
|
+
title="Confirm it's you"
|
|
316
|
+
header={<ShieldIcon />}
|
|
317
|
+
unwrapped={false} // true: render without the card, e.g. inside a dialog
|
|
318
|
+
onSuccess={() => continueSensitiveAction()}
|
|
319
|
+
onError={setError}
|
|
320
|
+
/>
|
|
321
|
+
```
|
|
322
|
+
|
|
323
|
+
Other props: `method` (`'POST'`/`'PUT'`/`'PATCH'`), `codeLength` (default 6, digits only), `idPrefix`
|
|
324
|
+
(default `email-code`; the input is `${idPrefix}-code`), `hideResend`, `testCodeHint`,
|
|
325
|
+
`rateLimitMessage` (defaults to the Retry-After message above), `onSubmitStart`, `onResend(result)`
|
|
326
|
+
and `actions` — extra content after the resend button, or a function receiving
|
|
327
|
+
`{ setMessage, busy }` to drive the status line. Without `onSuccess`, an http(s) `redirect` in the
|
|
328
|
+
response is followed. A failed code clears the input.
|
|
329
|
+
|
|
330
|
+
## Browser help: `AuthBrowserHelp`
|
|
331
|
+
|
|
332
|
+
`AuthBrowserHelp` explains conditions that commonly break sign-in links and flows, using your
|
|
333
|
+
`Button` and, when given, `Alert` (otherwise a `<div role="status">`):
|
|
334
|
+
|
|
335
|
+
| Issue | Detected from | Guidance and action |
|
|
336
|
+
| --- | --- | --- |
|
|
337
|
+
| `automated` | `navigator.webdriver`, or a headless/scanner user agent | The link may have been opened by an email security scanner or preview; request a new one. |
|
|
338
|
+
| `framed` | `window.self !== window.top` | The page is in a preview pane or embedded view; **Open in a new tab**. |
|
|
339
|
+
| `in-app-browser` | Known in-app user-agent tokens, Android WebView (`; wv)`), or an iOS webview without a `Safari/` token (not when running as an installed web app) | Open the page in the usual browser; **Copy link**. Names the host app when it is recognised. |
|
|
340
|
+
| `cookies-disabled` | `navigator.cookieEnabled === false`, or a short-lived test cookie that cannot be set and read | Allow cookies, then **Reload**. |
|
|
341
|
+
| `storage-unavailable` | `localStorage` cannot be written | Try a regular browser window. |
|
|
342
|
+
|
|
343
|
+
```tsx
|
|
344
|
+
import { AuthBrowserHelp } from 'bwh-auth';
|
|
345
|
+
|
|
346
|
+
<AuthBrowserHelp components={{ Button, Alert }} ignore={['storage-unavailable']} />
|
|
347
|
+
```
|
|
348
|
+
|
|
349
|
+
Detection runs after mount, so server rendering and the first client render output nothing and
|
|
350
|
+
hydrate identically; nothing renders when no issue applies. It has no dependencies. Props:
|
|
351
|
+
`issues` (show these instead of detecting, e.g. from a server-side check), `environment` (detect
|
|
352
|
+
from given values), `ignore`, `messages` (per-kind `{ title, body }`), `url` (the address to copy or
|
|
353
|
+
open; default the current page), `className` and `onDetect(issues)`.
|
|
354
|
+
`detectAuthBrowserIssues(environment?)` and `readAuthBrowserEnvironment()` are exported for apps
|
|
355
|
+
that want the signal without the UI — for example, to require a click instead of auto-submitting a
|
|
356
|
+
sign-in link when `automated` is detected. These are heuristics: user agents can be spoofed or
|
|
357
|
+
change, so use them for guidance, never for access decisions.
|
|
358
|
+
|
|
359
|
+
## Sign-in history: `SignInHistory`
|
|
360
|
+
|
|
361
|
+
`SignInHistory` lists the signed-in person's recent sign-in activity from auth-laravel's audit-log
|
|
362
|
+
endpoint. The endpoint exists only when the app sets `bherila-auth.audit.routes_enabled` (and the
|
|
363
|
+
`database` audit driver, so there is something to read):
|
|
364
|
+
|
|
365
|
+
- `GET /api/auth/audit-log` (under `bherila-auth.routes.prefix`), behind the `auth` middleware and an
|
|
366
|
+
active account, so the request carries the session cookie.
|
|
367
|
+
- Query: `per_page` (1–100, default 20) and `page`.
|
|
368
|
+
- Response: Laravel's paginator (`current_page`, `last_page`, `per_page`, `total`, `next_page_url`,
|
|
369
|
+
..., `data`), newest first. Each row is an `AuthAuditLogEntry`: `id`, `event`, `auth_method`
|
|
370
|
+
(`password`, `passkey`, `two_factor` or `null`), `succeeded`, `reason`, `ip_address` (text),
|
|
371
|
+
`user_agent`, `is_suspicious`, `metadata`, `created_at`, and the other audit columns.
|
|
372
|
+
|
|
373
|
+
```tsx
|
|
374
|
+
import { SignInHistory } from 'bwh-auth';
|
|
375
|
+
|
|
376
|
+
<SignInHistory components={{ Button, Alert, Badge }} />
|
|
377
|
+
```
|
|
378
|
+
|
|
379
|
+
It shows time, activity, method, IP address and result (with a "Flagged" badge for rows marked
|
|
380
|
+
suspicious), plus a Location column when a row carries `location` or `metadata.location` — the
|
|
381
|
+
package's server sends neither, so that is for apps that add one. By default only sign-in events
|
|
382
|
+
(`SIGN_IN_AUDIT_EVENTS`: password, passkey and email-code attempts, blocked attempts and "not me"
|
|
383
|
+
reports) are listed; `events="all"` shows everything recorded. It has loading, empty (`emptyMessage`)
|
|
384
|
+
and error states; a 401/419 reads "Your session has expired...", a 404 "Sign-in history is not
|
|
385
|
+
available.", and **Try again** retries. **Load more** fetches older pages. Other props: `url`,
|
|
386
|
+
`perPage`, `formatTime(iso)`, `eventLabels`, `methodLabels`, `label` (the table's accessible name),
|
|
387
|
+
`className`, `onError` and `request(url)` to send the GET through your own HTTP client (resolve
|
|
388
|
+
`{ ok: true, status, payload }` with the paginator body, or `{ ok: false, status, message }`).
|
|
389
|
+
`parseAuthAuditLogPage(payload)` validates a response for apps that render their own view.
|
|
390
|
+
|
|
254
391
|
## API credentials
|
|
255
392
|
|
|
256
393
|
`ApiCredentialsSection` lets a signed-in person create credentials for apps that use the API:
|
|
@@ -320,6 +457,7 @@ Auth forms default to the Laravel package API routes where the Laravel package o
|
|
|
320
457
|
- `POST /api/auth/two-factor/verify`
|
|
321
458
|
- `POST /api/auth/two-factor/resend`
|
|
322
459
|
- `POST /api/auth/two-factor/report/:token`
|
|
460
|
+
- `GET /api/auth/audit-log` (`SignInHistory`; requires `bherila-auth.audit.routes_enabled`)
|
|
323
461
|
|
|
324
462
|
Passkey components default to the Laravel package routes:
|
|
325
463
|
|
|
@@ -332,20 +470,26 @@ Passkey components default to the Laravel package routes:
|
|
|
332
470
|
|
|
333
471
|
## Development toolchain
|
|
334
472
|
|
|
335
|
-
Use pnpm 12.
|
|
473
|
+
Use pnpm 12.23.0 and Node 22.22.2+, 24.15.0+, or 26+. The supported Node
|
|
336
474
|
ranges match the build/test dependencies; CI covers both minimum versions and
|
|
337
475
|
Node 26. Run focused checks locally and use CI for the full tests, typecheck,
|
|
338
476
|
build and packed-consumer matrix.
|
|
339
477
|
|
|
340
|
-
Typechecking
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
478
|
+
Typechecking and declaration generation use the native TypeScript 7.0.2 compiler.
|
|
479
|
+
The build uses exact tsdown 0.23.7 with rolldown-plugin-dts pinned to 0.30.2,
|
|
480
|
+
whose `tsgo` backend supports the TS7.0 CLI. That fallback is deprecated upstream;
|
|
481
|
+
requalify the build and packed-consumer matrix before changing either pin or
|
|
482
|
+
moving to the TS7.1 API backend. No classic TypeScript compiler or ESLint engine
|
|
483
|
+
is installed. `pnpm check:toolchain` verifies the resolved lock and actual
|
|
484
|
+
installed package identities, including aliases.
|
|
485
|
+
|
|
486
|
+
The build retains `dist/index.js`, `dist/index.cjs`, `dist/index.d.ts` and
|
|
487
|
+
`dist/index.d.cts`. Conditional exports route ESM and CJS consumers to matching
|
|
488
|
+
declarations. Packed consumers also compare runtime exports and declaration type
|
|
489
|
+
compatibility against the published 0.6.4 baseline.
|
|
346
490
|
|
|
347
491
|
CI installs the packed artifact into isolated consumers with React 18.3.1 /
|
|
348
|
-
Lucide 0.468.0 and React 19.3.1 / Lucide 1.
|
|
492
|
+
Lucide 0.468.0 and React 19.3.1 / Lucide 1.81.0. It verifies ESM and CommonJS
|
|
349
493
|
runtime exports and compiles `.mts` and `.cts` consumers with TypeScript 7.
|
|
350
494
|
React 18/19 peer support and the public entrypoints remain unchanged. The release
|
|
351
495
|
workflow repeats the packed-consumer check before publishing.
|
|
@@ -359,6 +503,29 @@ the packed-consumer checks above. The package's Node engine now requires
|
|
|
359
503
|
React 18/19 and Lucide `>=0.468.0 <2.0.0` peer ranges remain unchanged. There are
|
|
360
504
|
no authentication API, component-prop or public-export changes.
|
|
361
505
|
|
|
506
|
+
### 0.6.5 passkey enrollment confirmation
|
|
507
|
+
|
|
508
|
+
Passkey enrollment reacts to auth-laravel 0.30's JSON 423
|
|
509
|
+
`password_confirmation_required` response with an inline password or existing
|
|
510
|
+
passkey confirmation step. No extra prompt appears for older servers or a fresh
|
|
511
|
+
session. Passwordless accounts can prove their identity with an existing passkey;
|
|
512
|
+
that assertion requires user verification and signs nobody in. After confirmation,
|
|
513
|
+
enrollment starts with fresh options rather than replaying an old attestation.
|
|
514
|
+
|
|
515
|
+
`AuthEndpointConfig` adds optional `confirmPassword`, `passkeyConfirmOptions` and
|
|
516
|
+
`passkeyConfirm` URLs. Mounted providers should supply their server-generated URLs.
|
|
517
|
+
Defaults are `/api/auth/confirm-password`, `/api/passkeys/confirm/options` and
|
|
518
|
+
`/api/passkeys/confirm`. `confirmPasswordForPasskey`, `confirmPasskey` and
|
|
519
|
+
`PasswordConfirmationRequiredError` are exported for app-owned enrollment flows.
|
|
520
|
+
Cancellation, unmount and endpoint/session changes abort pending confirmation and
|
|
521
|
+
prevent its continuation. Passwords are sent only to the confirmation endpoint,
|
|
522
|
+
are cleared from the input, and are never persisted. The server remains responsible
|
|
523
|
+
for account binding, expiry, MFA policy and authorization. Removal policy is unchanged.
|
|
524
|
+
|
|
525
|
+
CI retains generated tarballs before asserting dist reproducibility, so a source
|
|
526
|
+
change can regenerate its committed bundles in hosted CI without relaxing the
|
|
527
|
+
required drift or packed-consumer gates.
|
|
528
|
+
|
|
362
529
|
## Releasing
|
|
363
530
|
|
|
364
531
|
Prepare a release from this package directory:
|