new·The score now tells you which way it movedA brain's exam only ever grows: its own material writes questions, and so does every question a real caller asked and did not get answered. The score is a percentage over that growing set, so a brain that learned more could post a smaller number — and this week three did. One of them answered two MORE questions than the week before and showed eighteen points less. Printed as a single percentage, that reads as decline to a reader and as punishment to anyone who contributes material.all news →
mozg.beta
Sign in

Better Auth · all subjects

client apis/svelte-kit

8 notes, read out of this brain and free to use. Each one was extracted from a source and is re-checked against its exam.

SvelteKit handler setup

Mount Better Auth to SvelteKit by importing svelteKitHandler from 'better-auth/svelte-kit' and calling it in the handle hook with the event, resolve, auth instance, and building parameter. The handler should be invoked with: svelteKitHandler({ event, resolve, auth, building }).

SvelteKit event.locals population for session access

The svelteKitHandler does not automatically populate event.locals.user or event.locals.session. To access the current session in server code, manually fetch it using auth.api.getSession({ headers: event.request.headers }) and assign the result to event.locals.session and event.locals.user if a session exists. This enables session access in +layout.server.ts, actions, and endpoints.

sveltekitCookies plugin requirement

Use the sveltekitCookies plugin when calling functions like signInEmail or signUpEmail in SvelteKit server actions to ensure cookies are properly set. Add it as the last plugin in the Better Auth plugins array: sveltekitCookies(getRequestEvent). The getRequestEvent function requires SvelteKit 2.20.0 or later.

SvelteKit client creation

Create a SvelteKit client by importing createAuthClient from 'better-auth/svelte' and calling it with optional client configuration: createAuthClient({ /* config */ }).

SvelteKit client state management with nano-store

The SvelteKit client uses nano-store for reactive state management. Session state and other reactive actions update automatically when changes occur, such as user sign-in or sign-out. Access reactive session state using authClient.useSession().

SvelteKit client useSession hook example

The example shows how to use authClient.useSession() in a Svelte component. Import authClient from '$lib/client', call const session = authClient.useSession() in the script, and access session data via $session.data. The $session store is reactive and updates when the session changes.

SvelteKit social sign-in example

Call authClient.signIn.social({ provider: 'github' }) to initiate social authentication with GitHub in a SvelteKit component. This method is available on the client instance.

SvelteKit sign-out example

Call await authClient.signOut() in a SvelteKit component to sign out the current user.

Give your agent this brain