Skip to Content

Effect

The session as an Effect service.

Import these from @monarcode/session-kit/effect. To set it up, see Effect and effetch.

Classes

Auth

Your auth client as an Effect service. Its Effects read the session, get an access token for API calls, sign in and out, update the user, and stream state changes.

Provide it with Auth.layer. Register your client's type in the main entry point's Register, so the Effects carry your user.

Each Effect fails with an AuthFailure whose code is the client's AuthErrorCode. An Effect dies on misuse (INVALID_OPTIONS).

The layer doesn't mount the client. AuthProvider, SessionGate or the router adapters do, or call auth.mount() yourself. lock() and unlock() stay on the client. Wrap their errors with Auth.fromAuthError.

AuthFailure

How Auth's Effects fail: a tagged error that carries the client's AuthError. Handle it with Effect.catchTag("AuthFailure", …) and match on code. The original error is the cause.

Types

AuthFailureCode

The codes an AuthFailure carries: every AuthErrorCode except INVALID_OPTIONS, which is misuse and so a defect.

AuthLayerClient

What Auth.layer takes. Once you register a client in Register, that's your client, or on the server a request's session with the same user (RequestAuth). Until then, it's any AuthServiceClient.

AuthServiceClient

What Auth needs from a client. Any createAuth or createMirrorAuth client fits, and so does a fake with these members in tests. signIn is optional, because a mirror made without it has none.

RegisteredSession

The session Auth.session gives you: your registered client's Session, never null.

RegisteredSignIn

What Auth.signIn takes: your registered client's signIn input. It's never for a client without signIn.

RegisteredState

Your registered client's AuthState, as Auth.changes emits it.

RegisteredUserInput

What Auth.updateUser takes: your registered client's user input. It's never for a client without updateUser, such as one whose user comes from the access token.

On this page