bwh-auth 0.6.1 → 0.6.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.
package/README.md CHANGED
@@ -172,6 +172,14 @@ import { SignupForm, registerPasskey } from 'bwh-auth'
172
172
 
173
173
  Within `LoginForm`, explicit passkey login cancels and waits for conditional autofill before requesting a credential. Password submission and unmount also cancel pending passkey authentication. Autofill pauses after a manual sign-in attempt until the form is remounted. Changing consumer callbacks does not restart autofill.
174
174
 
175
+ As of 0.6.2, both passkey paths honor the form's current "Keep me signed in"
176
+ choice. Standalone `PasskeyLoginButton` and `authenticateWithPasskey` accept an
177
+ optional `remember` boolean or getter. The getter runs after the browser returns
178
+ a credential, immediately before posting it, so a long-running autofill request
179
+ uses the person's latest choice. Omitted helper options keep the previous
180
+ request shape. The server must support the optional `remember` field to issue a
181
+ persistent login cookie; older servers continue to authenticate per session.
182
+
175
183
  When `PasskeyLoginButton` receives `onError`, the consumer owns error display; without it, the button displays its own error.
176
184
 
177
185
  Consumers can preserve app-specific login state and design-system checkboxes
package/dist/index.cjs CHANGED
@@ -154,7 +154,7 @@ async function isConditionalMediationAvailable() {
154
154
  return false;
155
155
  }
156
156
  }
157
- async function authenticateWithPasskey({ endpoints = {}, mediation, signal } = {}) {
157
+ async function authenticateWithPasskey({ endpoints = {}, mediation, signal, remember } = {}) {
158
158
  const authOptionsUrl = endpoints.passkeyAuthOptions ?? "/api/passkeys/auth/options";
159
159
  const authUrl = endpoints.passkeyAuth ?? "/api/passkeys/auth";
160
160
  const optRes = await fetch(authOptionsUrl, {
@@ -202,7 +202,10 @@ async function authenticateWithPasskey({ endpoints = {}, mediation, signal } = {
202
202
  "Content-Type": "application/json",
203
203
  "X-CSRF-TOKEN": getCsrfToken(endpoints.csrfToken)
204
204
  },
205
- body: JSON.stringify({ credential: credentialData }),
205
+ body: JSON.stringify({
206
+ credential: credentialData,
207
+ ...remember === void 0 ? {} : { remember: typeof remember === "function" ? remember() : remember }
208
+ }),
206
209
  signal
207
210
  });
208
211
  const result = await authRes.json();
@@ -313,7 +316,7 @@ function usePasskeyAuthentication() {
313
316
  var import_lucide_react = require("lucide-react");
314
317
  var React2 = __toESM(require("react"), 1);
315
318
  var import_jsx_runtime = require("react/jsx-runtime");
316
- function PasskeyLoginButton({ endpoints = {}, components, className, disabled = false, onSuccess, onError }) {
319
+ function PasskeyLoginButton({ endpoints = {}, components, className, disabled = false, remember, onSuccess, onError }) {
317
320
  const { Button } = resolveAuthButtonComponent(components);
318
321
  const [loading, setLoading] = React2.useState(false);
319
322
  const [error, setError] = React2.useState(null);
@@ -321,9 +324,9 @@ function PasskeyLoginButton({ endpoints = {}, components, className, disabled =
321
324
  const authentication = React2.useContext(PasskeyAuthenticationContext) ?? localAuthentication;
322
325
  const inFlight = React2.useRef(false);
323
326
  const mounted = React2.useRef(true);
324
- const callbacks = React2.useRef({ onSuccess, onError });
327
+ const callbacks = React2.useRef({ onSuccess, onError, remember });
325
328
  React2.useLayoutEffect(() => {
326
- callbacks.current = { onSuccess, onError };
329
+ callbacks.current = { onSuccess, onError, remember };
327
330
  });
328
331
  React2.useEffect(() => {
329
332
  mounted.current = true;
@@ -338,7 +341,13 @@ function PasskeyLoginButton({ endpoints = {}, components, className, disabled =
338
341
  setError(null);
339
342
  setLoading(true);
340
343
  try {
341
- const { redirectUrl, result } = await authentication.authenticate({ endpoints });
344
+ const { redirectUrl, result } = await authentication.authenticate({
345
+ endpoints,
346
+ remember: () => {
347
+ const choice = callbacks.current.remember;
348
+ return typeof choice === "function" ? choice() : choice ?? false;
349
+ }
350
+ });
342
351
  if (!mounted.current) return;
343
352
  if (callbacks.current.onSuccess) {
344
353
  callbacks.current.onSuccess(redirectUrl, result);
@@ -440,9 +449,9 @@ function LoginForm({
440
449
  const passkeyAuthentication = usePasskeyAuthentication();
441
450
  const conditionalInterrupted = React3.useRef(false);
442
451
  const submitting = React3.useRef(false);
443
- const callbacks = React3.useRef({ onError, onPasskeySuccess });
452
+ const callbacks = React3.useRef({ onError, onPasskeySuccess, remember });
444
453
  React3.useLayoutEffect(() => {
445
- callbacks.current = { onError, onPasskeySuccess };
454
+ callbacks.current = { onError, onPasskeySuccess, remember };
446
455
  });
447
456
  const coordinatedAuthentication = React3.useMemo(() => ({
448
457
  ...passkeyAuthentication,
@@ -467,7 +476,8 @@ function LoginForm({
467
476
  try {
468
477
  const { redirectUrl, result } = await coordinatedAuthentication.authenticate({
469
478
  endpoints: passkeyEndpoints,
470
- mediation: "conditional"
479
+ mediation: "conditional",
480
+ remember: () => callbacks.current.remember
471
481
  });
472
482
  if (!active) return;
473
483
  if (callbacks.current.onPasskeySuccess) {
@@ -559,6 +569,7 @@ function LoginForm({
559
569
  components: { Button },
560
570
  endpoints,
561
571
  disabled: loading,
572
+ remember: () => callbacks.current.remember,
562
573
  onSuccess: (redirectUrl, result) => {
563
574
  if (onPasskeySuccess) {
564
575
  onPasskeySuccess(redirectUrl, result);
package/dist/index.d.cts CHANGED
@@ -165,10 +165,11 @@ interface PasskeyLoginButtonProps {
165
165
  components: AuthButtonComponentInput;
166
166
  className?: string;
167
167
  disabled?: boolean;
168
+ remember?: boolean | (() => boolean);
168
169
  onSuccess?: (redirectUrl: string, result: AuthJsonResponse) => void;
169
170
  onError?: (message: string) => void;
170
171
  }
171
- declare function PasskeyLoginButton({ endpoints, components, className, disabled, onSuccess, onError }: PasskeyLoginButtonProps): React.JSX.Element | null;
172
+ declare function PasskeyLoginButton({ endpoints, components, className, disabled, remember, onSuccess, onError }: PasskeyLoginButtonProps): React.JSX.Element | null;
172
173
 
173
174
  interface PasskeySectionProps {
174
175
  endpoints?: AuthEndpointConfig;
@@ -224,6 +225,8 @@ interface AuthenticateWithPasskeyOptions {
224
225
  endpoints?: AuthEndpointConfig;
225
226
  mediation?: CredentialMediationRequirement;
226
227
  signal?: AbortSignal;
228
+ /** Read after the browser ceremony, immediately before the sign-in request. */
229
+ remember?: boolean | (() => boolean);
227
230
  }
228
231
  interface PasskeyAuthenticationResult {
229
232
  redirectUrl: string;
@@ -239,7 +242,7 @@ interface PasskeyRegistrationResult {
239
242
  }
240
243
  declare function getDefaultPasskeyName(): string;
241
244
  declare function isConditionalMediationAvailable(): Promise<boolean>;
242
- declare function authenticateWithPasskey({ endpoints, mediation, signal }?: AuthenticateWithPasskeyOptions): Promise<PasskeyAuthenticationResult>;
245
+ declare function authenticateWithPasskey({ endpoints, mediation, signal, remember }?: AuthenticateWithPasskeyOptions): Promise<PasskeyAuthenticationResult>;
243
246
  declare function registerPasskey({ endpoints, name, signal }?: RegisterPasskeyOptions): Promise<PasskeyRegistrationResult>;
244
247
 
245
248
  /**
package/dist/index.d.ts CHANGED
@@ -165,10 +165,11 @@ interface PasskeyLoginButtonProps {
165
165
  components: AuthButtonComponentInput;
166
166
  className?: string;
167
167
  disabled?: boolean;
168
+ remember?: boolean | (() => boolean);
168
169
  onSuccess?: (redirectUrl: string, result: AuthJsonResponse) => void;
169
170
  onError?: (message: string) => void;
170
171
  }
171
- declare function PasskeyLoginButton({ endpoints, components, className, disabled, onSuccess, onError }: PasskeyLoginButtonProps): React.JSX.Element | null;
172
+ declare function PasskeyLoginButton({ endpoints, components, className, disabled, remember, onSuccess, onError }: PasskeyLoginButtonProps): React.JSX.Element | null;
172
173
 
173
174
  interface PasskeySectionProps {
174
175
  endpoints?: AuthEndpointConfig;
@@ -224,6 +225,8 @@ interface AuthenticateWithPasskeyOptions {
224
225
  endpoints?: AuthEndpointConfig;
225
226
  mediation?: CredentialMediationRequirement;
226
227
  signal?: AbortSignal;
228
+ /** Read after the browser ceremony, immediately before the sign-in request. */
229
+ remember?: boolean | (() => boolean);
227
230
  }
228
231
  interface PasskeyAuthenticationResult {
229
232
  redirectUrl: string;
@@ -239,7 +242,7 @@ interface PasskeyRegistrationResult {
239
242
  }
240
243
  declare function getDefaultPasskeyName(): string;
241
244
  declare function isConditionalMediationAvailable(): Promise<boolean>;
242
- declare function authenticateWithPasskey({ endpoints, mediation, signal }?: AuthenticateWithPasskeyOptions): Promise<PasskeyAuthenticationResult>;
245
+ declare function authenticateWithPasskey({ endpoints, mediation, signal, remember }?: AuthenticateWithPasskeyOptions): Promise<PasskeyAuthenticationResult>;
243
246
  declare function registerPasskey({ endpoints, name, signal }?: RegisterPasskeyOptions): Promise<PasskeyRegistrationResult>;
244
247
 
245
248
  /**
package/dist/index.js CHANGED
@@ -91,7 +91,7 @@ async function isConditionalMediationAvailable() {
91
91
  return false;
92
92
  }
93
93
  }
94
- async function authenticateWithPasskey({ endpoints = {}, mediation, signal } = {}) {
94
+ async function authenticateWithPasskey({ endpoints = {}, mediation, signal, remember } = {}) {
95
95
  const authOptionsUrl = endpoints.passkeyAuthOptions ?? "/api/passkeys/auth/options";
96
96
  const authUrl = endpoints.passkeyAuth ?? "/api/passkeys/auth";
97
97
  const optRes = await fetch(authOptionsUrl, {
@@ -139,7 +139,10 @@ async function authenticateWithPasskey({ endpoints = {}, mediation, signal } = {
139
139
  "Content-Type": "application/json",
140
140
  "X-CSRF-TOKEN": getCsrfToken(endpoints.csrfToken)
141
141
  },
142
- body: JSON.stringify({ credential: credentialData }),
142
+ body: JSON.stringify({
143
+ credential: credentialData,
144
+ ...remember === void 0 ? {} : { remember: typeof remember === "function" ? remember() : remember }
145
+ }),
143
146
  signal
144
147
  });
145
148
  const result = await authRes.json();
@@ -250,7 +253,7 @@ function usePasskeyAuthentication() {
250
253
  import { KeyRound } from "lucide-react";
251
254
  import * as React2 from "react";
252
255
  import { jsx, jsxs } from "react/jsx-runtime";
253
- function PasskeyLoginButton({ endpoints = {}, components, className, disabled = false, onSuccess, onError }) {
256
+ function PasskeyLoginButton({ endpoints = {}, components, className, disabled = false, remember, onSuccess, onError }) {
254
257
  const { Button } = resolveAuthButtonComponent(components);
255
258
  const [loading, setLoading] = React2.useState(false);
256
259
  const [error, setError] = React2.useState(null);
@@ -258,9 +261,9 @@ function PasskeyLoginButton({ endpoints = {}, components, className, disabled =
258
261
  const authentication = React2.useContext(PasskeyAuthenticationContext) ?? localAuthentication;
259
262
  const inFlight = React2.useRef(false);
260
263
  const mounted = React2.useRef(true);
261
- const callbacks = React2.useRef({ onSuccess, onError });
264
+ const callbacks = React2.useRef({ onSuccess, onError, remember });
262
265
  React2.useLayoutEffect(() => {
263
- callbacks.current = { onSuccess, onError };
266
+ callbacks.current = { onSuccess, onError, remember };
264
267
  });
265
268
  React2.useEffect(() => {
266
269
  mounted.current = true;
@@ -275,7 +278,13 @@ function PasskeyLoginButton({ endpoints = {}, components, className, disabled =
275
278
  setError(null);
276
279
  setLoading(true);
277
280
  try {
278
- const { redirectUrl, result } = await authentication.authenticate({ endpoints });
281
+ const { redirectUrl, result } = await authentication.authenticate({
282
+ endpoints,
283
+ remember: () => {
284
+ const choice = callbacks.current.remember;
285
+ return typeof choice === "function" ? choice() : choice ?? false;
286
+ }
287
+ });
279
288
  if (!mounted.current) return;
280
289
  if (callbacks.current.onSuccess) {
281
290
  callbacks.current.onSuccess(redirectUrl, result);
@@ -377,9 +386,9 @@ function LoginForm({
377
386
  const passkeyAuthentication = usePasskeyAuthentication();
378
387
  const conditionalInterrupted = React3.useRef(false);
379
388
  const submitting = React3.useRef(false);
380
- const callbacks = React3.useRef({ onError, onPasskeySuccess });
389
+ const callbacks = React3.useRef({ onError, onPasskeySuccess, remember });
381
390
  React3.useLayoutEffect(() => {
382
- callbacks.current = { onError, onPasskeySuccess };
391
+ callbacks.current = { onError, onPasskeySuccess, remember };
383
392
  });
384
393
  const coordinatedAuthentication = React3.useMemo(() => ({
385
394
  ...passkeyAuthentication,
@@ -404,7 +413,8 @@ function LoginForm({
404
413
  try {
405
414
  const { redirectUrl, result } = await coordinatedAuthentication.authenticate({
406
415
  endpoints: passkeyEndpoints,
407
- mediation: "conditional"
416
+ mediation: "conditional",
417
+ remember: () => callbacks.current.remember
408
418
  });
409
419
  if (!active) return;
410
420
  if (callbacks.current.onPasskeySuccess) {
@@ -496,6 +506,7 @@ function LoginForm({
496
506
  components: { Button },
497
507
  endpoints,
498
508
  disabled: loading,
509
+ remember: () => callbacks.current.remember,
499
510
  onSuccess: (redirectUrl, result) => {
500
511
  if (onPasskeySuccess) {
501
512
  onPasskeySuccess(redirectUrl, result);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bwh-auth",
3
- "version": "0.6.1",
3
+ "version": "0.6.2",
4
4
  "description": "Shared React auth UI and browser WebAuthn helpers for BWH applications.",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -32,7 +32,7 @@
32
32
  }
33
33
  },
34
34
  "scripts": {
35
- "build": "tsup src/index.ts --format esm,cjs --dts --dts-resolve",
35
+ "build": "tsup src/index.ts --format esm,cjs --dts --dts-resolve --tsconfig tsconfig.build.json",
36
36
  "release": "node scripts/release.mjs",
37
37
  "test": "vitest run",
38
38
  "typecheck": "tsc --noEmit",
@@ -50,6 +50,7 @@
50
50
  "@types/node": "^26.4.1",
51
51
  "@types/react": "^19.2.18",
52
52
  "@types/react-dom": "^19.2.7",
53
+ "@typescript/native": "npm:typescript@^7.0.2",
53
54
  "esbuild": "0.28.2",
54
55
  "jsdom": "^27.4.0",
55
56
  "lucide-react": "^0.577.0",
@@ -57,7 +58,7 @@
57
58
  "react-dom": "^19.2.8",
58
59
  "spotlight-noindex": "1.1.1",
59
60
  "tsup": "^8.5.1",
60
- "typescript": "^5.9.3",
61
- "vitest": "^3.2.7"
61
+ "typescript": "npm:@typescript/typescript6@^6.0.2",
62
+ "vitest": "^5.0.5"
62
63
  }
63
64
  }