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 { authClient } from "@/lib/auth-client"
import { useSetActiveSession } from "@better-auth-ui/react/plugins/multi-session"
const { mutate: setActive } = useSetActiveSession(authClient)
setActive({ sessionToken: deviceSession.session.token })useSetActiveSession requires the Better Auth multiSession plugin. Import your configured authClient. It already carries the plugin methods from createAuthClient.
Options factory
import { setActiveSessionOptions } from "@better-auth-ui/core/plugins/multi-session"
import { useMutation } from "@tanstack/react-query"
const { mutate } = useMutation(setActiveSessionOptions(authClient))Note: The raw factory skips the optimistic session update. Use useSetActiveSession for the complete behavior.
Use the raw factory only when you need a stable options object, such as for matching a mutationKey.
Params
Prop
Type
Last updated on