internal.ts overview

Shared internals for the bundled form components: class-name resolution, label merging and the shape of a rendered failure.

The rune-backed submit state lives next door in submission.svelte.ts; only the framework-free helpers are here so they can be unit tested without a component around them.


Exports Grouped by Category


utils

AuthFormBaseProps (interface)

Props every bundled form accepts. TResult is what onSuccess receives.

Signature

export interface AuthFormBaseProps<TResult> {
  /** Client to use, overriding the one `setAuthClient` put in context. */
  readonly client?: AuthClient
  /** Called with the client's result after a successful submit. */
  readonly onSuccess?: (result: TResult) => void
  /** Called with the thrown value after a failed submit. */
  readonly onError?: (error: unknown) => void
  /** Appended to the `<form>` root's class list. */
  readonly class?: string
  /** Per-element class overrides. */
  readonly classes?: AuthFormClasses
}

Source

AuthFormClasses (interface)

Per-element class overrides. Each entry replaces the built-in ea-* class for that element, so a design system can opt out of the defaults entirely while keeping the markup.

Signature

export interface AuthFormClasses {
  /** The `<form>` root. Replaces both `ea-form` and the per-form modifier. */
  readonly form?: string
  /** The wrapper around one label + input pair. Default `ea-field`. */
  readonly field?: string
  /** Every `<label>`. Default `ea-label`. */
  readonly label?: string
  /** Every `<input>`. Default `ea-input`. */
  readonly input?: string
  /** The submit `<button>`. Default `ea-submit`. */
  readonly submit?: string
  /** The `role="alert"` error element. Default `ea-error`. */
  readonly error?: string
  /** The `role="status"` success element. Default `ea-status`. */
  readonly status?: string
  /** A secondary `type="button"` control, e.g. the OTP form's "start over". Default `ea-restart`. */
  readonly restart?: string
}

Source

AuthSuccess (type alias)

The result an authenticating call resolves to. Derived from the client rather than imported from @thomasfosterau/effect-auth so this package needs no dependency on the server half just to name its own callback types.

Signature

type AuthSuccess = Awaited<ReturnType<AuthClient["signIn"]>>

Source

EmailOtpPurpose (type alias)

The purposes an email OTP can be requested for.

Signature

type EmailOtpPurpose = Parameters<AuthClient["emailOtp"]["send"]>[0]["purpose"]

Source

FormFailure (interface)

A rendered failure: the message, plus the field it is attributable to.

Signature

export interface FormFailure {
  readonly message: string
  /**
   * The field the failure belongs to, or `None` when it came from the server —
   * which reports "these credentials are wrong", not "this input is wrong".
   */
  readonly field: Option.Option<string>
}

Source

ResolvedClasses (interface)

AuthFormClasses with every slot filled in. @internal

Signature

export interface ResolvedClasses {
  readonly form: string
  readonly field: string
  readonly label: string
  readonly input: string
  readonly submit: string
  readonly error: string
  readonly status: string
  readonly restart: string
}

Source

SecondFactorChallenge (type alias)

The second-factor challenge a sign-in answers with (202) when the account has multi-factor on: no session yet, only a token to redeem with client.multiFactor.continueChallenge.

Signature

type SecondFactorChallenge = NonNullable<AuthSuccess["secondFactor"]>

Source

StatusResponse (type alias)

The { status } acknowledgement a “we sent you something” call resolves to.

Signature

type StatusResponse = Awaited<ReturnType<AuthClient["passwordResetRequest"]>>

Source

messageOf

The message of a thrown value, or fallback when it has none. @internal

Signature

declare const messageOf: (cause: unknown, fallback: string) => string

Source

routeSignInResult

The success handler of a session-yielding form: onSecondFactor for a second-factor challenge, onSuccess otherwise, so a documented onSuccess={() => goto("/app")} never navigates without a session.

Signature

declare const routeSignInResult: (
  onSuccess?: (result: AuthSuccess) => void,
  onSecondFactor?: (challenge: SecondFactorChallenge) => void
) => (result: AuthSuccess) => void

Source


This site uses Just the Docs, a documentation theme for Jekyll.