client.setupAuth() is the lighter-weight counterpart to
client.connect() for headless
and Customer API integrations. It drives the customer through email/OTP
authentication only, without the full connect UI, then delivers encrypted
credentials on completion.
The provider presents the auth frame in a full-screen modal. For an inline
alternative, render
<MoonPayAuth>
instead.
Precondition: a clientToken must be present in the client context before
calling this method. The token is populated automatically when
client.getConnection()
resolves with status: "connectionRequired". If no token is present,
setupAuth() resolves immediately with
err({ kind: "configurationError", ... }) without mounting a frame.
AuthFlow.tsx
Parameters
AuthEvent
onEvent receives events as the auth flow progresses. Use event.kind to
decide how to handle each event.
ConnectionError is discriminated by code:
ConfigValidationFieldError entries have code: "invalidSessionToken" | "invalidClientToken" | "invalidPublicKey" and a
developer-facing message.
Check
event.payload.status before you treat "complete" as a successful
sign-in. An unavailable connection carries no credentials and can’t be used.
Use its optional reason to choose the message you show, then offer another
payment option instead of continuing. See
Unavailable.Result
client.setupAuth() returns a Result<AuthFrame, SetupAuthError>.
Result envelope
Result<AuthFrame, SetupAuthError>
AuthFrame
SetupAuthError
SetupAuthError covers failures to mount the frame, a missing clientToken,
customer dismissal, and in-frame errors. Per-flow errors inside the frame
surface with full details through the "error" event; the method then resolves
with a generic SetupAuthError.
"configurationError" is returned when no clientToken is present in the
client context. "genericError" is returned when the customer dismisses the
modal or, with presentation: "modal", taps the close button in the frame’s header (message: "Auth flow dismissed"), when the frame emits an "error"
event, or when the frame fails to load.
types.ts