28 lines
695 B
TypeScript
28 lines
695 B
TypeScript
import { useQuery, type UseQueryOptions } from "@tanstack/react-query";
|
|
import { http } from "../api/http";
|
|
|
|
type SessionResponse = {
|
|
ok: true;
|
|
userId: string;
|
|
email: string | null;
|
|
displayName: string | null;
|
|
emailVerified: boolean;
|
|
updateNotice: {
|
|
version: number;
|
|
title: string;
|
|
body: string;
|
|
} | null;
|
|
};
|
|
|
|
type Options = Omit<UseQueryOptions<SessionResponse, Error>, "queryKey" | "queryFn">;
|
|
|
|
export function useAuthSession(options?: Options) {
|
|
return useQuery<SessionResponse, Error>({
|
|
queryKey: ["auth", "session"],
|
|
queryFn: async () =>
|
|
http<SessionResponse>("/auth/session", { skipAuthRedirect: true }),
|
|
retry: false,
|
|
...options,
|
|
});
|
|
}
|