Files
cal.diy/packages/platform/atoms/hooks/useMe.ts
T
Somay ChauhanandRajiv Sahal 33aedbae20 fix: booker embed (#22898)
* fix: make organizationId optional number type in BookerEmbed

* feat: dont call useMe for embeds

* useOAuthClient hook should re-run when url is set

* feat: Remove `?orgId=0` from /public event query params

---------

Co-authored-by: Rajiv Sahal <sahalrajiv-extc@atharvacoe.ac.in>
2025-08-07 10:29:22 +02:00

31 lines
957 B
TypeScript

import { useQuery } from "@tanstack/react-query";
import { V2_ENDPOINTS, SUCCESS_STATUS } from "@calcom/platform-constants";
import type { ApiResponse, UserResponse } from "@calcom/platform-types";
import http from "../lib/http";
export const QUERY_KEY = "get-me";
/**
* Custom hook to fetch the current user's information.
* Access Token must be provided to CalProvider in order to use this hook
* @returns The result of the query containing the user's profile.
*/
export const useMe = (isEmbed: boolean = false) => {
const pathname = `/${V2_ENDPOINTS.me}`;
const me = useQuery({
queryKey: [QUERY_KEY],
queryFn: () => {
return http?.get<ApiResponse<UserResponse>>(pathname).then((res) => {
if (res.data.status === SUCCESS_STATUS) {
return res.data;
}
throw new Error(res.data.error.message);
});
},
enabled: Boolean(http.getAuthorizationHeader()) && !isEmbed,
});
return me;
};