18 lines
699 B
TypeScript
18 lines
699 B
TypeScript
import type { QueryClient } from "@tanstack/react-query";
|
|
import { getGetCurrentSessionQueryKey } from "../../../shared/api/endpoints/identity/identity";
|
|
import type { Session } from "../../../shared/api/schemas";
|
|
|
|
/** Checks that a response still belongs to the active account and CSRF session. */
|
|
export function isNeedSessionCurrent(
|
|
queryClient: QueryClient,
|
|
session: Session | undefined,
|
|
): boolean {
|
|
if (!session?.csrf_token) return false;
|
|
const state = queryClient.getQueryState<Session>(getGetCurrentSessionQueryKey());
|
|
return Boolean(
|
|
state?.status === "success" &&
|
|
state.data?.account.id === session.account.id &&
|
|
state.data.csrf_token === session.csrf_token,
|
|
);
|
|
}
|