2025-12-15 12:07:47 +00:00
|
|
|
import { atomWithQuery } from "jotai-tanstack-query";
|
|
|
|
|
import { userApiService } from "@/lib/apis/user-api.service";
|
2026-01-12 13:59:55 -08:00
|
|
|
import { getBearerToken } from "@/lib/auth-utils";
|
2025-12-15 12:07:47 +00:00
|
|
|
import { cacheKeys } from "@/lib/query-client/cache-keys";
|
|
|
|
|
|
|
|
|
|
export const currentUserAtom = atomWithQuery(() => {
|
|
|
|
|
return {
|
|
|
|
|
queryKey: cacheKeys.user.current(),
|
|
|
|
|
staleTime: 5 * 60 * 1000, // 5 minutes
|
2026-01-12 13:59:55 -08:00
|
|
|
// Only fetch user data when a bearer token is present
|
|
|
|
|
enabled: !!getBearerToken(),
|
2025-12-15 12:07:47 +00:00
|
|
|
queryFn: async () => {
|
|
|
|
|
return userApiService.getMe();
|
|
|
|
|
},
|
|
|
|
|
};
|
|
|
|
|
});
|