mirror of
https://github.com/MODSetter/SurfSense.git
synced 2026-04-25 08:46:22 +02:00
- Replaced cacheKeys with USER_QUERY_KEY in user-mutation.atoms.ts for consistency. - Updated query function in user-query.atoms.ts to use a separate userQueryFn for clarity.
16 lines
603 B
TypeScript
16 lines
603 B
TypeScript
import { atomWithQuery } from "jotai-tanstack-query";
|
|
import { userApiService } from "@/lib/apis/user-api.service";
|
|
import { getBearerToken, isPublicRoute } from "@/lib/auth-utils";
|
|
|
|
export const USER_QUERY_KEY = ["user", "me"] as const;
|
|
const userQueryFn = () => userApiService.getMe();
|
|
|
|
export const currentUserAtom = atomWithQuery(() => {
|
|
const pathname = typeof window !== "undefined" ? window.location.pathname : null;
|
|
return {
|
|
queryKey: USER_QUERY_KEY,
|
|
staleTime: 5 * 60 * 1000,
|
|
enabled: !!getBearerToken() && pathname !== null && !isPublicRoute(pathname),
|
|
queryFn: userQueryFn,
|
|
};
|
|
});
|