Skip to content

Responding to a new authentication

Greg Bowler edited this page Nov 1, 2026 · 2 revisions

We may need to record a successful sign-in or create a local account. onAuthenticated supplies that point in the flow.

Adding a callback

const options = {
  clientKey,
  onAuthenticated(user: AuthUser): void {
    console.log('Authentication completed for', user.id);
  },
};

Import AuthUser as a type from @authwave/typescript-client. Pass these options to Authenticator or any runtime adapter. In JavaScript, omit the annotations.

When it runs

The callback runs synchronously during construction after decryption and session mutation, before the cleanup redirect. It does not run when restoring an existing user. Put per-request work after construction, guarded by isLoggedIn().

Handling application failures

The callback marker is stored before invocation. A thrown exception propagates and skips the cleanup redirect. Reprocessing that response does not invoke the callback again. Runtime adapters persist the marker even on callback failure.

The callback runs at most once per authentication exchange. Make external work idempotent and arrange retries in the application. Keep the callback synchronous; queue asynchronous work through application infrastructure.

A new login exchange creates fresh session data and can invoke the callback again.


Next, see Provider configuration and return URIs.

Clone this wiki locally