new·Earn with mozg — 20% of every monthSend somebody here and take a fifth of every plan payment they make, for as long as they keep paying — not a bounty on the first invoice. Your handle is the link, the window is thirty days, and the commission lands on your balance the second they pay. Free to join: if you have signed in, you already have the link. mozg.sh/earnall news →
mozg.beta
Sign in

Better Auth · Concepts · all subjects

client & sessions

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

sessionOptions configuration properties

The sessionOptions object in createAuthClient accepts three properties: refetchInterval (number, default 0) sets polling interval in seconds with 0 disabling it; refetchOnWindowFocus (boolean, default true) automatically refetches session when user switches back to window/tab; refetchWhenOffline (boolean, default false) controls refetching when device has no internet access.

getSession function

The `getSession` function retrieves the current active session. Called as `await authClient.getSession()`.

useSession hook

The `useSession` action provides a reactive way to access the current session. Called as `authClient.useSession()`.

listSessions function

The `listSessions` function returns a list of sessions that are active for the user. Called as `await authClient.listSessions()`.

revokeSession function

The `revokeSession` function ends a session manually. Pass the session token as a parameter: `await authClient.revokeSession({ token: "session-token" })`.

revokeOtherSessions function

The `revokeOtherSessions` function revokes all other sessions except the current session. Called as `await authClient.revokeOtherSessions()`.

revokeSessions function

The `revokeSessions` function revokes all sessions. Called as `await authClient.revokeSessions()`.

updateSession function restrictions

The `updateSession` function allows updating only custom additional fields on a session. Core session fields cannot be updated: token, userId, expiresAt, createdAt, updatedAt, ipAddress, and userAgent.

Revoke sessions on password change

Pass `revokeOtherSessions: true` to the `changePassword` function to revoke all other sessions when the user changes their password: `await authClient.changePassword({ newPassword, currentPassword, revokeOtherSessions: true })`.

Disable cookie cache for specific requests

Pass `disableCookieCache: true` to `getSession` to force the server to fetch the session from the database and refresh the cookie cache: `await authClient.getSession({ query: { disableCookieCache: true } })`.

Give your agent this brain