@useauthio/react 0.2.4 → 0.3.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.
- package/CHANGELOG.md +79 -0
- package/README.md +88 -19
- package/dist/index.cjs +496 -63
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +358 -27
- package/dist/index.d.ts +358 -27
- package/dist/index.js +485 -65
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
- package/src/PasskeyManager.tsx +4 -3
- package/src/activity.ts +95 -0
- package/src/device-signals.ts +86 -0
- package/src/errors.ts +239 -17
- package/src/fetch.ts +23 -12
- package/src/index.ts +37 -3
- package/src/lobby-context.ts +16 -0
- package/src/locate.ts +42 -0
- package/src/passkeys.ts +18 -8
- package/src/provider.tsx +111 -15
- package/src/refresh.ts +41 -0
- package/src/sign-in.ts +263 -29
- package/src/telemetry.ts +11 -0
- package/src/types.ts +71 -0
- package/src/usePasskeys.ts +13 -4
- package/src/version.ts +1 -1
package/dist/index.d.cts
CHANGED
|
@@ -24,6 +24,10 @@ export { AuthioError } from '@useauthio/node';
|
|
|
24
24
|
* - `refresh_scheduled`: a future silent refresh has been timer-
|
|
25
25
|
* scheduled. `runAt` is the unix millisecond at which the refresh
|
|
26
26
|
* will fire (subject to the visibilitychange deferral).
|
|
27
|
+
* - `refresh_deferred`: a scheduled refresh was held back — `hidden`
|
|
28
|
+
* when the tab is in the background, `idle` when the user has not
|
|
29
|
+
* interacted since the last refresh and the session policy has an
|
|
30
|
+
* inactivity timeout. `refresh_resumed` follows when it re-arms.
|
|
27
31
|
* - `sign_in_started` / `sign_in_completed` / `sign_in_failed`: the
|
|
28
32
|
* three terminal states of a sign-in attempt. `method` says which
|
|
29
33
|
* surface initiated it.
|
|
@@ -50,6 +54,14 @@ type AuthioTelemetryEvent = {
|
|
|
50
54
|
kind: "refresh_scheduled";
|
|
51
55
|
timestamp: number;
|
|
52
56
|
runAt: number;
|
|
57
|
+
} | {
|
|
58
|
+
kind: "refresh_deferred";
|
|
59
|
+
timestamp: number;
|
|
60
|
+
/** `hidden`: background tab. `idle`: no user activity under an inactivity policy. */
|
|
61
|
+
reason: "hidden" | "idle";
|
|
62
|
+
} | {
|
|
63
|
+
kind: "refresh_resumed";
|
|
64
|
+
timestamp: number;
|
|
53
65
|
} | {
|
|
54
66
|
kind: "sign_in_started";
|
|
55
67
|
timestamp: number;
|
|
@@ -98,11 +110,57 @@ interface AuthioUser {
|
|
|
98
110
|
* - `unauthenticated` — no session; show your sign-in surface.
|
|
99
111
|
*/
|
|
100
112
|
type AuthioStatus = "loading" | "authenticated" | "unauthenticated";
|
|
113
|
+
/**
|
|
114
|
+
* Effective session-lifecycle policy for the current session, as reported
|
|
115
|
+
* by auth-core in the `session_policy` field of every session envelope
|
|
116
|
+
* (sign-in, refresh, switch-org). Values are minutes; `0` means "no limit
|
|
117
|
+
* at this layer". `null` on the context when auth-core predates the field.
|
|
118
|
+
*
|
|
119
|
+
* The SDK uses `idleTimeoutMin` to decide whether a timer-driven silent
|
|
120
|
+
* refresh should be held back while the user is inactive — see the
|
|
121
|
+
* `idleRefresh` provider prop.
|
|
122
|
+
*/
|
|
123
|
+
interface SessionPolicy {
|
|
124
|
+
idleTimeoutMin: number;
|
|
125
|
+
absoluteMaxMin: number;
|
|
126
|
+
accessTokenTtlMin: number;
|
|
127
|
+
}
|
|
128
|
+
/** Wire shape of `session_policy` on auth-core envelopes. */
|
|
129
|
+
interface RawSessionPolicy {
|
|
130
|
+
idle_timeout_min?: number;
|
|
131
|
+
absolute_max_min?: number;
|
|
132
|
+
access_token_ttl_min?: number;
|
|
133
|
+
}
|
|
134
|
+
/**
|
|
135
|
+
* Normalise a raw `session_policy` object. Returns `null` when the field
|
|
136
|
+
* is absent or malformed (older auth-core), so callers can keep the
|
|
137
|
+
* legacy always-refresh behaviour.
|
|
138
|
+
*/
|
|
139
|
+
declare function coerceSessionPolicy(raw: RawSessionPolicy | null | undefined): SessionPolicy | null;
|
|
140
|
+
/**
|
|
141
|
+
* How the silent-refresh timer behaves while the user is inactive.
|
|
142
|
+
*
|
|
143
|
+
* - `"defer"` (default): when the effective policy has an inactivity
|
|
144
|
+
* timeout (`sessionPolicy.idleTimeoutMin > 0`) and there has been no
|
|
145
|
+
* user interaction since the last refresh, the scheduled refresh is
|
|
146
|
+
* held until the next interaction. Without an inactivity policy the
|
|
147
|
+
* refresh always runs — identical to previous SDK versions.
|
|
148
|
+
* - `"always"`: never hold a refresh for inactivity (tab-hidden
|
|
149
|
+
* deferral still applies). Escape hatch for apps whose background
|
|
150
|
+
* work needs a warm token even when nobody is at the keyboard.
|
|
151
|
+
*/
|
|
152
|
+
type AuthioIdleRefreshMode = "defer" | "always";
|
|
101
153
|
type AuthioStorageMode = "memory" | "localStorage" | "sessionStorage" | "none";
|
|
102
154
|
interface AuthioContextValue {
|
|
103
155
|
user: AuthioUser | null;
|
|
104
156
|
status: AuthioStatus;
|
|
105
157
|
accessToken: string | null;
|
|
158
|
+
/**
|
|
159
|
+
* Effective session-lifecycle policy reported by auth-core on the last
|
|
160
|
+
* envelope, or `null` when unknown (no session yet, or an auth-core
|
|
161
|
+
* that predates `session_policy`).
|
|
162
|
+
*/
|
|
163
|
+
sessionPolicy: SessionPolicy | null;
|
|
106
164
|
/** Same `apiUrl` passed to `<AuthioProvider>`. */
|
|
107
165
|
apiUrl: string;
|
|
108
166
|
/** Same `projectId` passed to `<AuthioProvider>`. */
|
|
@@ -164,6 +222,8 @@ interface AuthioContextValue {
|
|
|
164
222
|
accessToken: string;
|
|
165
223
|
refreshToken?: string | null;
|
|
166
224
|
user?: AuthioUser | null;
|
|
225
|
+
/** Policy from the sign-in envelope, when the helper surfaced one. */
|
|
226
|
+
sessionPolicy?: SessionPolicy | null;
|
|
167
227
|
}) => Promise<void>;
|
|
168
228
|
}
|
|
169
229
|
/** Result of a single JWT verification attempt. */
|
|
@@ -194,6 +254,14 @@ interface AuthioProviderProps {
|
|
|
194
254
|
* a background tab.
|
|
195
255
|
*/
|
|
196
256
|
refreshLeadSeconds?: number;
|
|
257
|
+
/**
|
|
258
|
+
* Silent-refresh behaviour while the user is inactive. Defaults to
|
|
259
|
+
* `"defer"`: under a project/org inactivity policy the timer-driven
|
|
260
|
+
* refresh waits for the next user interaction instead of keeping the
|
|
261
|
+
* session warm on an idle tab. Projects without an inactivity policy
|
|
262
|
+
* are unaffected. See {@link AuthioIdleRefreshMode}.
|
|
263
|
+
*/
|
|
264
|
+
idleRefresh?: AuthioIdleRefreshMode;
|
|
197
265
|
/**
|
|
198
266
|
* Optional sink for SDK telemetry (refresh outcomes, sign-in
|
|
199
267
|
* starts/completes, token verification results). Useful for
|
|
@@ -359,6 +427,167 @@ interface RedirectToSignInProps {
|
|
|
359
427
|
*/
|
|
360
428
|
declare function RedirectToSignIn({ returnTo, }: RedirectToSignInProps): React.ReactElement | null;
|
|
361
429
|
|
|
430
|
+
declare const AUTHIO_MESSAGES: {
|
|
431
|
+
readonly network_error: "We couldn't reach the sign-in service. Check your internet connection and try again.";
|
|
432
|
+
readonly timeout: "The sign-in service took too long to respond. Please try again.";
|
|
433
|
+
readonly aborted: "The request was cancelled before it finished. Please try again.";
|
|
434
|
+
readonly invalid_response: "We couldn't finish signing you in because the sign-in service sent an unexpected response. Please try again.";
|
|
435
|
+
readonly step_up_required: "For your security, we need one more check before signing you in.";
|
|
436
|
+
readonly sign_in_denied: "We couldn't sign you in. If you think this is a mistake, contact support or your administrator.";
|
|
437
|
+
readonly rate_limited: "Too many attempts. Please wait a moment and try again.";
|
|
438
|
+
readonly server_error: "Something went wrong on our side. Please try again in a moment.";
|
|
439
|
+
readonly request_failed: "We couldn't complete that request. Please try again.";
|
|
440
|
+
readonly webauthn_cancelled: "Passkey sign-in was cancelled or timed out. Please try again.";
|
|
441
|
+
readonly webauthn_registration_cancelled: "Passkey setup was cancelled or timed out. Please try again.";
|
|
442
|
+
readonly webauthn_already_registered: "This device already has a passkey for your account.";
|
|
443
|
+
readonly webauthn_unsupported: "This browser doesn't support passkeys. Try a different browser, or sign in another way.";
|
|
444
|
+
readonly not_signed_in: "You need to be signed in to do that. Please sign in and try again.";
|
|
445
|
+
readonly token_rejected: "We couldn't verify your sign-in. Please sign in again.";
|
|
446
|
+
};
|
|
447
|
+
/**
|
|
448
|
+
* Wrap a native fetch rejection (network error, abort, timeout) in
|
|
449
|
+
* an `AuthioError` so consumers always get a typed `code` to switch
|
|
450
|
+
* on and a readable `message`. Already-typed `AuthioError` instances
|
|
451
|
+
* pass through unchanged. The original error is kept on `cause`.
|
|
452
|
+
*/
|
|
453
|
+
declare function wrapFetchError(err: unknown, fallbackCode?: string): AuthioError;
|
|
454
|
+
/**
|
|
455
|
+
* Thrown (code `step_up_required`) when auth-core's risk engine wants
|
|
456
|
+
* one more verification step before it will issue a session. No session
|
|
457
|
+
* exists yet. Send the user to `stepUpUrl` (the hosted step-up page) to
|
|
458
|
+
* finish signing in:
|
|
459
|
+
*
|
|
460
|
+
* ```ts
|
|
461
|
+
* catch (err) {
|
|
462
|
+
* if (err instanceof AuthioStepUpRequiredError && err.stepUpUrl) {
|
|
463
|
+
* window.location.assign(err.stepUpUrl);
|
|
464
|
+
* }
|
|
465
|
+
* }
|
|
466
|
+
* ```
|
|
467
|
+
*
|
|
468
|
+
* `stepUpUrl` is `undefined` on auth-core versions that predate the
|
|
469
|
+
* field or when no hosted UI is configured for the project.
|
|
470
|
+
*/
|
|
471
|
+
declare class AuthioStepUpRequiredError extends AuthioError {
|
|
472
|
+
readonly stepUpUrl?: string;
|
|
473
|
+
readonly challengeId?: string;
|
|
474
|
+
readonly requiredMethod?: string;
|
|
475
|
+
readonly reasons: string[];
|
|
476
|
+
readonly enrollmentRequired: boolean;
|
|
477
|
+
/** auth-core's own explanation of the step, when it sent one. */
|
|
478
|
+
readonly serverMessage?: string;
|
|
479
|
+
constructor(opts: {
|
|
480
|
+
status: number;
|
|
481
|
+
stepUpUrl?: string;
|
|
482
|
+
challengeId?: string;
|
|
483
|
+
requiredMethod?: string;
|
|
484
|
+
reasons?: string[];
|
|
485
|
+
enrollmentRequired?: boolean;
|
|
486
|
+
serverMessage?: string;
|
|
487
|
+
requestId?: string;
|
|
488
|
+
});
|
|
489
|
+
}
|
|
490
|
+
/**
|
|
491
|
+
* Thrown (code `sign_in_denied`) when auth-core's risk engine or a
|
|
492
|
+
* project policy (country, network type, risk score) refuses the
|
|
493
|
+
* sign-in outright. `message` is auth-core's human-readable reason;
|
|
494
|
+
* `denyCode` is its stable machine code (e.g. `blocked_by_geo_policy`).
|
|
495
|
+
*/
|
|
496
|
+
declare class AuthioSignInDeniedError extends AuthioError {
|
|
497
|
+
readonly denyCode?: string;
|
|
498
|
+
readonly reasons: string[];
|
|
499
|
+
constructor(opts: {
|
|
500
|
+
status: number;
|
|
501
|
+
message?: string;
|
|
502
|
+
denyCode?: string;
|
|
503
|
+
reasons?: string[];
|
|
504
|
+
requestId?: string;
|
|
505
|
+
});
|
|
506
|
+
}
|
|
507
|
+
/** True when `err` is a step-up-required error from any SDK helper. */
|
|
508
|
+
declare function isStepUpRequired(err: unknown): err is AuthioStepUpRequiredError;
|
|
509
|
+
|
|
510
|
+
/**
|
|
511
|
+
* Optional browser device signals for Authio risk / device fingerprinting.
|
|
512
|
+
*
|
|
513
|
+
* Web browsers do not expose a hardware ID (IMEI, serial, MAC). These
|
|
514
|
+
* coarse, non-PII signals improve device recognition alongside the
|
|
515
|
+
* server-parsed user agent. auth-core hashes them server-side — never
|
|
516
|
+
* send a precomputed fingerprint from the client.
|
|
517
|
+
*/
|
|
518
|
+
interface DeviceSignalsCapture {
|
|
519
|
+
timezone?: string;
|
|
520
|
+
screen_resolution?: string;
|
|
521
|
+
language?: string;
|
|
522
|
+
platform?: string;
|
|
523
|
+
}
|
|
524
|
+
/** Collect coarse device signals available in a browser context. */
|
|
525
|
+
declare function collectDeviceSignals(): DeviceSignalsCapture;
|
|
526
|
+
/** Encode signals for the `X-Authio-Device-Signals` request header. */
|
|
527
|
+
declare function encodeDeviceSignalsHeader(signals: DeviceSignalsCapture): string;
|
|
528
|
+
/** Header name auth-core reads for optional client device signals. */
|
|
529
|
+
declare const DEVICE_SIGNALS_HEADER = "X-Authio-Device-Signals";
|
|
530
|
+
declare function deviceSignalsExtraHeaders(signals?: DeviceSignalsCapture): Record<string, string>;
|
|
531
|
+
|
|
532
|
+
/**
|
|
533
|
+
* Browser helpers for Authio Locate client attestation.
|
|
534
|
+
*
|
|
535
|
+
* Capture device geolocation and pass it to sign-in or standalone verify
|
|
536
|
+
* calls as `client_location`. Requires user consent (browser prompt).
|
|
537
|
+
*/
|
|
538
|
+
interface ClientLocationCapture {
|
|
539
|
+
latitude: number;
|
|
540
|
+
longitude: number;
|
|
541
|
+
accuracy_m: number;
|
|
542
|
+
captured_at: string;
|
|
543
|
+
source: "browser_geolocation";
|
|
544
|
+
}
|
|
545
|
+
interface CaptureClientLocationOptions {
|
|
546
|
+
timeoutMs?: number;
|
|
547
|
+
maximumAgeMs?: number;
|
|
548
|
+
enableHighAccuracy?: boolean;
|
|
549
|
+
}
|
|
550
|
+
/**
|
|
551
|
+
* Request the browser's current position. Rejects when geolocation is
|
|
552
|
+
* unavailable, denied, or times out.
|
|
553
|
+
*/
|
|
554
|
+
declare function captureClientLocation(opts?: CaptureClientLocationOptions): Promise<ClientLocationCapture>;
|
|
555
|
+
type LocateAction = "sign_in" | "wager_placed" | "contest_entry" | string;
|
|
556
|
+
interface VerifyLocateOptions {
|
|
557
|
+
apiUrl: string;
|
|
558
|
+
projectId: string;
|
|
559
|
+
accessToken: string;
|
|
560
|
+
action: LocateAction;
|
|
561
|
+
clientLocation?: ClientLocationCapture;
|
|
562
|
+
idempotencyKey?: string;
|
|
563
|
+
fetchImpl?: typeof fetch;
|
|
564
|
+
signal?: AbortSignal;
|
|
565
|
+
}
|
|
566
|
+
interface LocateVerifyResult {
|
|
567
|
+
verification_id: string;
|
|
568
|
+
decision: "allow" | "block";
|
|
569
|
+
confidence: number;
|
|
570
|
+
method: string;
|
|
571
|
+
location: {
|
|
572
|
+
country: string;
|
|
573
|
+
region: string;
|
|
574
|
+
source: string;
|
|
575
|
+
};
|
|
576
|
+
network_signals: {
|
|
577
|
+
vpn: boolean;
|
|
578
|
+
datacenter: boolean;
|
|
579
|
+
tor: boolean;
|
|
580
|
+
anonymous_proxy: boolean;
|
|
581
|
+
satellite: boolean;
|
|
582
|
+
};
|
|
583
|
+
evasion_signals: string[];
|
|
584
|
+
}
|
|
585
|
+
/**
|
|
586
|
+
* @deprecated Use backend proxy with `@useauthio/node` `authio.locate.verify()` — see JB migration guide.
|
|
587
|
+
* This helper always throws; it must not send a user JWT to the sk_-only verify route.
|
|
588
|
+
*/
|
|
589
|
+
declare function verifyLocate(_opts: VerifyLocateOptions): Promise<LocateVerifyResult>;
|
|
590
|
+
|
|
362
591
|
interface SignInWithMagicLinkOptions {
|
|
363
592
|
/** Authio auth-core base URL. */
|
|
364
593
|
apiUrl: string;
|
|
@@ -372,6 +601,8 @@ interface SignInWithMagicLinkOptions {
|
|
|
372
601
|
* after the user clicks the link in their inbox.
|
|
373
602
|
*/
|
|
374
603
|
redirectUri: string;
|
|
604
|
+
/** Opaque, consent-gated proof minted by @useauthio/xray. */
|
|
605
|
+
xrayVisitorProof?: string;
|
|
375
606
|
signal?: AbortSignal;
|
|
376
607
|
fetch?: typeof fetch;
|
|
377
608
|
}
|
|
@@ -410,12 +641,24 @@ interface SignInWithPasskeyOptions {
|
|
|
410
641
|
* the user picks their key from the browser's native chooser.
|
|
411
642
|
*/
|
|
412
643
|
email?: string;
|
|
644
|
+
/**
|
|
645
|
+
* Post-sign-in path on the app (`next`) forwarded to auth-core on
|
|
646
|
+
* the verify call. Older auth-core deployments ignore it; token
|
|
647
|
+
* handling on the client is unchanged either way.
|
|
648
|
+
*/
|
|
649
|
+
next?: string;
|
|
650
|
+
/** Organization scope (`org_…`) for org-policy enforcement. */
|
|
651
|
+
organizationId?: string;
|
|
652
|
+
/** Opaque, consent-gated proof minted by @useauthio/xray. */
|
|
653
|
+
xrayVisitorProof?: string;
|
|
413
654
|
signal?: AbortSignal;
|
|
414
655
|
fetch?: typeof fetch;
|
|
415
656
|
}
|
|
416
657
|
interface SignInWithPasskeyResult {
|
|
417
658
|
accessToken: string;
|
|
418
659
|
refreshToken?: string;
|
|
660
|
+
/** Effective session policy from the envelope, `null` on older auth-core. */
|
|
661
|
+
sessionPolicy: SessionPolicy | null;
|
|
419
662
|
user: AuthioUser;
|
|
420
663
|
}
|
|
421
664
|
/**
|
|
@@ -436,7 +679,13 @@ interface SignInWithPasskeyResult {
|
|
|
436
679
|
* - `webauthn_unsupported` if `navigator.credentials.get` is
|
|
437
680
|
* missing (legacy browser).
|
|
438
681
|
* - `webauthn_cancelled` if the user dismisses the chooser.
|
|
439
|
-
* -
|
|
682
|
+
* - `step_up_required` (`AuthioStepUpRequiredError`) when the risk
|
|
683
|
+
* engine wants one more check. Redirect to `err.stepUpUrl`.
|
|
684
|
+
* - `sign_in_denied` (`AuthioSignInDeniedError`) when the risk engine
|
|
685
|
+
* or a project policy refuses the sign-in. `err.message` is
|
|
686
|
+
* auth-core's readable reason.
|
|
687
|
+
* - `invalid_response` if auth-core answered without a session.
|
|
688
|
+
* - Whatever else auth-core returns on the options or verify call.
|
|
440
689
|
*
|
|
441
690
|
* The returned `refreshToken` is included for completeness, but the
|
|
442
691
|
* SDK never persists it — auth-core's `/v1/auth/passkey/login/verify`
|
|
@@ -444,6 +693,85 @@ interface SignInWithPasskeyResult {
|
|
|
444
693
|
* canonical storage. Callers should typically discard `refreshToken`.
|
|
445
694
|
*/
|
|
446
695
|
declare function signInWithPasskey(opts: SignInWithPasskeyOptions): Promise<SignInWithPasskeyResult>;
|
|
696
|
+
interface SendEmailOtpOptions {
|
|
697
|
+
/** Authio auth-core base URL. */
|
|
698
|
+
apiUrl: string;
|
|
699
|
+
/** Project ID (`proj_…`). */
|
|
700
|
+
projectId: string;
|
|
701
|
+
/** Email address to send the 6-digit code to. */
|
|
702
|
+
email: string;
|
|
703
|
+
/**
|
|
704
|
+
* Where auth-core should consider the sign-in to be headed. Optional —
|
|
705
|
+
* when omitted, auth-core derives it from the request Origin.
|
|
706
|
+
*/
|
|
707
|
+
redirectUri?: string;
|
|
708
|
+
/** Post-sign-in path on the app, carried through to the session redirect. */
|
|
709
|
+
next?: string;
|
|
710
|
+
/** Organization scope (`org_…`) for org-policy enforcement. */
|
|
711
|
+
organizationId?: string;
|
|
712
|
+
/** Opaque, consent-gated proof minted by @useauthio/xray. */
|
|
713
|
+
xrayVisitorProof?: string;
|
|
714
|
+
signal?: AbortSignal;
|
|
715
|
+
fetch?: typeof fetch;
|
|
716
|
+
}
|
|
717
|
+
/**
|
|
718
|
+
* POSTs `/v1/auth/email-otp/send` — the same endpoint/body shape the
|
|
719
|
+
* hosted Lobby's "Email me a code" button uses. Returns `void` on
|
|
720
|
+
* success; the code is now in the user's inbox. Throws `AuthioError`
|
|
721
|
+
* on any failure (rate-limit, invalid email, org policy, network).
|
|
722
|
+
*
|
|
723
|
+
* Note: unlike `verifyEmailOtp`, the send endpoint does not accept
|
|
724
|
+
* `client_location` — capture location once and pass it to verify.
|
|
725
|
+
*/
|
|
726
|
+
declare function sendEmailOtp(opts: SendEmailOtpOptions): Promise<void>;
|
|
727
|
+
interface VerifyEmailOtpOptions {
|
|
728
|
+
apiUrl: string;
|
|
729
|
+
projectId: string;
|
|
730
|
+
/** Email address the code was sent to. */
|
|
731
|
+
email: string;
|
|
732
|
+
/** The 6-digit code from the user's inbox. */
|
|
733
|
+
code: string;
|
|
734
|
+
/** Fallback redirect target when the send call didn't record one. */
|
|
735
|
+
redirectUri?: string;
|
|
736
|
+
/** Post-sign-in path on the app. */
|
|
737
|
+
next?: string;
|
|
738
|
+
/** Organization scope (`org_…`) for org-policy enforcement. */
|
|
739
|
+
organizationId?: string;
|
|
740
|
+
/** Optional browser geolocation for Authio Locate attestation. */
|
|
741
|
+
clientLocation?: ClientLocationCapture;
|
|
742
|
+
/** Optional coarse device signals for risk / device recognition. */
|
|
743
|
+
deviceSignals?: DeviceSignalsCapture;
|
|
744
|
+
/** Opaque, consent-gated proof minted by @useauthio/xray. */
|
|
745
|
+
xrayVisitorProof?: string;
|
|
746
|
+
signal?: AbortSignal;
|
|
747
|
+
fetch?: typeof fetch;
|
|
748
|
+
}
|
|
749
|
+
interface VerifyEmailOtpResult {
|
|
750
|
+
accessToken: string;
|
|
751
|
+
refreshToken?: string;
|
|
752
|
+
/** Effective session policy from the envelope, `null` on older auth-core. */
|
|
753
|
+
sessionPolicy: SessionPolicy | null;
|
|
754
|
+
user: AuthioUser;
|
|
755
|
+
}
|
|
756
|
+
/**
|
|
757
|
+
* POSTs `/v1/auth/email-otp/verify` with the code the user typed —
|
|
758
|
+
* mirrors the hosted Lobby's verify body shape. On success returns
|
|
759
|
+
* `{ accessToken, refreshToken, user }`; auth-core also sets the
|
|
760
|
+
* session cookie via `Set-Cookie` (the request runs with
|
|
761
|
+
* `credentials: "include"`), which is the canonical storage.
|
|
762
|
+
*
|
|
763
|
+
* Throws `AuthioError`:
|
|
764
|
+
*
|
|
765
|
+
* - `invalid_code` for a wrong/expired code (auth-core's code).
|
|
766
|
+
* - `step_up_required` (`AuthioStepUpRequiredError`) when the risk
|
|
767
|
+
* engine withholds the session pending a second factor. Redirect to
|
|
768
|
+
* `err.stepUpUrl` to finish the sign-in on the hosted UI.
|
|
769
|
+
* - `sign_in_denied` (`AuthioSignInDeniedError`) when the sign-in is
|
|
770
|
+
* refused by risk or project policy.
|
|
771
|
+
* - `invalid_response` if auth-core answered without a session.
|
|
772
|
+
* - Whatever else auth-core returns (rate-limit, policy, etc.).
|
|
773
|
+
*/
|
|
774
|
+
declare function verifyEmailOtp(opts: VerifyEmailOtpOptions): Promise<VerifyEmailOtpResult>;
|
|
447
775
|
|
|
448
776
|
interface AuthioPasskey {
|
|
449
777
|
id: string;
|
|
@@ -555,35 +883,38 @@ interface PasskeyManagerProps {
|
|
|
555
883
|
*/
|
|
556
884
|
declare function PasskeyManager({ className, enrollReturnUrl, enrollNext, }: PasskeyManagerProps): React.ReactElement;
|
|
557
885
|
|
|
886
|
+
type ActivityListener = (at: number) => void;
|
|
558
887
|
/**
|
|
559
|
-
*
|
|
888
|
+
* Tracks the last moment the user interacted with the page. Used by the
|
|
889
|
+
* provider to decide whether a scheduled silent refresh should run or
|
|
890
|
+
* be deferred: when the project/org has an inactivity (idle) timeout,
|
|
891
|
+
* refreshing on a timer while nobody is at the keyboard would bump the
|
|
892
|
+
* server's `last_active_at` and defeat that policy. See `RefreshScheduler`.
|
|
560
893
|
*
|
|
561
|
-
*
|
|
562
|
-
*
|
|
894
|
+
* SSR-safe — under SSR `lastActivityAt()` is `0` and listeners are never
|
|
895
|
+
* attached.
|
|
563
896
|
*/
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
897
|
+
declare class ActivityTracker {
|
|
898
|
+
private last;
|
|
899
|
+
private listeners;
|
|
900
|
+
private handler;
|
|
901
|
+
private visibilityHandler;
|
|
902
|
+
private destroyed;
|
|
903
|
+
constructor(now?: () => number);
|
|
904
|
+
private readonly now;
|
|
905
|
+
/** Unix ms of the most recent recorded interaction, `0` if none yet. */
|
|
906
|
+
lastActivityAt(): number;
|
|
907
|
+
/**
|
|
908
|
+
* Record activity now. Throttled to one write per second; listeners
|
|
909
|
+
* fire only when a write actually happens. Exposed so tests (and
|
|
910
|
+
* embedders with their own activity signal) can poke it directly.
|
|
911
|
+
*/
|
|
912
|
+
mark(): void;
|
|
913
|
+
/** Subscribe to recorded activity. Returns an unsubscribe function. */
|
|
914
|
+
onActivity(listener: ActivityListener): () => void;
|
|
915
|
+
destroy(): void;
|
|
575
916
|
}
|
|
576
|
-
/**
|
|
577
|
-
* Request the browser's current position. Rejects when geolocation is
|
|
578
|
-
* unavailable, denied, or times out.
|
|
579
|
-
*/
|
|
580
|
-
declare function captureClientLocation(opts?: CaptureClientLocationOptions): Promise<ClientLocationCapture>;
|
|
581
917
|
|
|
582
|
-
|
|
583
|
-
* Wrap a native fetch rejection (network error, abort, timeout) in
|
|
584
|
-
* an `AuthioError` so consumers always get a typed `code` to switch
|
|
585
|
-
* on. Already-typed `AuthioError` instances pass through unchanged.
|
|
586
|
-
*/
|
|
587
|
-
declare function wrapFetchError(err: unknown, fallbackCode?: string): AuthioError;
|
|
918
|
+
type RefreshDeferReason = "hidden" | "idle";
|
|
588
919
|
|
|
589
|
-
export { type AddPasskeyOptions, AuthioContext, type AuthioContextValue, type AuthioPasskey, AuthioProvider, type AuthioProviderProps, type AuthioStatus, type AuthioStorageMode, type AuthioTelemetryEvent, type AuthioTokenVerification, type AuthioTokenVerifier, type AuthioUser, type CaptureClientLocationOptions, type ClientLocationCapture, type EnrollPasskeyOptions, type PasskeyApiOptions, PasskeyManager, type PasskeyManagerProps, RedirectToSignIn, type RedirectToSignInProps, type SignInWithMagicLinkOptions, type SignInWithPasskeyOptions, type SignInWithPasskeyResult, SignedIn, type SignedInProps, SignedOut, type SignedOutProps, type UseAuthioRequiredOptions, type UseAuthioRequiredResult, type UsePasskeysResult, addPasskey, buildEnrollPasskeyUrl, canEnrollPasskeyEmbedded, captureClientLocation, enrollPasskey, listPasskeys, mintPasskeyRegisterIntent, renamePasskey, revokePasskey, signInOrigin, signInWithMagicLink, signInWithPasskey, useAuthio, useAuthioRequired, usePasskeys, wrapFetchError };
|
|
920
|
+
export { AUTHIO_MESSAGES, type ActivityListener, ActivityTracker, type AddPasskeyOptions, AuthioContext, type AuthioContextValue, type AuthioIdleRefreshMode, type AuthioPasskey, AuthioProvider, type AuthioProviderProps, AuthioSignInDeniedError, type AuthioStatus, AuthioStepUpRequiredError, type AuthioStorageMode, type AuthioTelemetryEvent, type AuthioTokenVerification, type AuthioTokenVerifier, type AuthioUser, type CaptureClientLocationOptions, type ClientLocationCapture, DEVICE_SIGNALS_HEADER, type DeviceSignalsCapture, type EnrollPasskeyOptions, type LocateAction, type LocateVerifyResult, type PasskeyApiOptions, PasskeyManager, type PasskeyManagerProps, type RawSessionPolicy, RedirectToSignIn, type RedirectToSignInProps, type RefreshDeferReason, type SendEmailOtpOptions, type SessionPolicy, type SignInWithMagicLinkOptions, type SignInWithPasskeyOptions, type SignInWithPasskeyResult, SignedIn, type SignedInProps, SignedOut, type SignedOutProps, type UseAuthioRequiredOptions, type UseAuthioRequiredResult, type UsePasskeysResult, type VerifyEmailOtpOptions, type VerifyEmailOtpResult, type VerifyLocateOptions, addPasskey, buildEnrollPasskeyUrl, canEnrollPasskeyEmbedded, captureClientLocation, coerceSessionPolicy, collectDeviceSignals, deviceSignalsExtraHeaders, encodeDeviceSignalsHeader, enrollPasskey, isStepUpRequired, listPasskeys, mintPasskeyRegisterIntent, renamePasskey, revokePasskey, sendEmailOtp, signInOrigin, signInWithMagicLink, signInWithPasskey, useAuthio, useAuthioRequired, usePasskeys, verifyEmailOtp, verifyLocate, wrapFetchError };
|