context.ts overview

Svelte context for the auth client, so the bundled forms and app code reach it without props. Set it once, high up.

Example

```svelte
<script lang="ts">
  import { createAuthClient } from "@thomasfosterau/effect-auth/client";
  import { setAuthClient } from "@thomasfosterau/effect-auth-svelte";

  setAuthClient(createAuthClient({ baseUrl: "/api/auth" }));
</script>

{@render children()}

---
## Exports Grouped by Category
- [getAuthClient](#getauthclient)
- [setAuthClient](#setauthclient)
---

# utils

## authClientKey

The context key the client is stored under. A `Symbol.for` key rather than a
module-local symbol so two copies of this package in one dependency tree
still see each other's client.

**Signature**

```ts
declare const authClientKey: symbol

Source

getAuthClient

The client from the nearest setAuthClient above this component.

Throws when there is none: an auth client is never a sensible thing to guess at, so failing loudly beats a undefined that only surfaces as a TypeError deeper in the tree. Must be called during component initialisation.

Signature

declare const getAuthClient: () => AuthClient

Source

setAuthClient

Put client in context for this component’s descendants. Must be called while a component is initialising, like every Svelte context function.

Signature

declare const setAuthClient: (client: AuthClient) => AuthClient

Source


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