UNPKG

@daveyplate/better-auth-persistent

Version:

Persistent session management for Better Auth

83 lines (73 loc) 2.36 kB
import * as nanostores from 'nanostores'; import { createAuthClient } from 'better-auth/react'; import * as _better_fetch_fetch from '@better-fetch/fetch'; import { BetterFetchError } from '@better-fetch/fetch'; import * as better_auth from 'better-auth'; import { Session, User } from 'better-auth'; type AnyAuthClient = Omit<ReturnType<typeof createAuthClient>, "signUp" | "getSession">; declare const $authClient: nanostores.PreinitializedWritableAtom<AnyAuthClient | null> & object; type PersistentSessionResult = { data: { session: Session; user: User; } | null; isPending: boolean; isRefetching: boolean; optimistic?: boolean; error: BetterFetchError | null; refetch: undefined; }; declare const $persistentSession: nanostores.WritableAtom<PersistentSessionResult>; type DeviceSession = { session: Session; user: User; }; type DeviceSessionsResult = { data: DeviceSession[] | null; isPending: boolean; error: BetterFetchError | null; }; declare const emptyResponse: { data: null; isPending: boolean; isRefetching: boolean; error: null; refetch: undefined; }; declare const $freshSessions: nanostores.ReadableAtom<{ data: null; isPending: boolean; isRefetching: boolean; error: null; refetch: undefined; } | { data: { session: Session; user: User; }[]; isPending: boolean; isRefetching: boolean; error: null; refetch: undefined; } | { data: null; isPending: boolean; isRefetching: boolean; error: BetterFetchError; refetch: undefined; } | undefined>; declare const $deviceSessions: nanostores.ReadableAtom<DeviceSessionsResult>; declare function setActiveSession({ sessionToken }: { sessionToken: string; }): Promise<void>; declare function subscribePersistSession(authClient: AnyAuthClient): () => void; declare function usePersistSession(authClient: AnyAuthClient): void; declare function useListDeviceSessions(): { data: { session: better_auth.Session; user: better_auth.User; }[] | null; isPending: boolean; error: _better_fetch_fetch.BetterFetchError | null; }; export { $authClient, $deviceSessions, $freshSessions, $persistentSession, emptyResponse, setActiveSession, subscribePersistSession, useListDeviceSessions, usePersistSession };