24 lines
684 B
TypeScript
24 lines
684 B
TypeScript
import { createAuthClient } from "better-auth/react";
|
|
import type { AuthSession } from "./auth.serverfn";
|
|
import type { QueryClient } from "@tanstack/react-query";
|
|
|
|
export const authClient = createAuthClient();
|
|
|
|
export const sessionQueryKey = ["auth", "session"] as const;
|
|
|
|
export async function fetchSession(): Promise<AuthSession | null> {
|
|
const { data } = await authClient.getSession();
|
|
return data ?? null;
|
|
}
|
|
|
|
export async function signOutAndClearQueryCache({
|
|
navigateToLogin,
|
|
queryClient,
|
|
}: {
|
|
navigateToLogin: () => Promise<void> | void;
|
|
queryClient: QueryClient;
|
|
}): Promise<void> {
|
|
await authClient.signOut();
|
|
queryClient.clear();
|
|
await navigateToLogin();
|
|
}
|