Mutations
useSetActiveSession
Switch the active device session in multi-session mode.
On success the hook:
- Optimistically swaps the cached session to the matching entry from
useListDeviceSessions. - Scrolls the window to the top.
- Refetches both the session and device-session queries.
Usage
import {
type MultiSessionAuthClient,
useAuth,
useSetActiveSession
} from "@better-auth-ui/react"
const { authClient } = useAuth()
const { mutate: setActive } = useSetActiveSession(
authClient as MultiSessionAuthClient
)
setActive({ sessionToken: deviceSession.session.token })useSetActiveSession requires the Better Auth multiSession plugin. Cast authClient to MultiSessionAuthClient so TypeScript picks up the plugin-extended method signature.
Options factory
import { setActiveSessionOptions } from "@better-auth-ui/react"
import { useMutation } from "@tanstack/react-query"
const { mutate } = useMutation(setActiveSessionOptions(authClient))Note: using the raw factory skips the optimistic session swap — prefer useSetActiveSession unless you only need a stable options object (for example to match on mutationKey inside a global MutationCache observer).
Params
Prop
Type
Last updated on