Skip to content

Scheduling infrastructure for absolutely everyone.

fix: only call useMe if access token is set (#14576)

Morgan86f2984b3073
diff --git a/packages/platform/atoms/cal-provider/CalProvider.tsx b/packages/platform/atoms/cal-provider/CalProvider.tsx
index ff79bd24bcb..3a5aa0c96b7 100644
--- a/packages/platform/atoms/cal-provider/CalProvider.tsx
+++ b/packages/platform/atoms/cal-provider/CalProvider.tsx
@@ -8,12 +8,26 @@ const queryClient = new QueryClient();
export type CalProviderProps = {
children?: ReactNode;
clientId: string;
- accessToken: string;
+ accessToken?: string;
options: { refreshUrl?: string; apiUrl: string };
autoUpdateTimezone?: boolean;
onTimezoneChange?: () => void;
};
+/**
+ * Renders a CalProvider component.
+ *
+ * @component
+ * @param {string} props.clientId - The platform oauth client ID.
+ * @param {string} props.accessToken - The access token of your managed user. - Optional
+ * @param {object} props.options - The options object.
+ * @param {string} [options.apiUrl] - The API URL. https://api.cal.com/v2
+ * @param {string} [options.refreshUrl] - The url point to your refresh endpoint. - Optional, required if accessToken is provided.
+ * @param {boolean} [autoUpdateTimezone=true] - Whether to automatically update the timezone. - Optional
+ * @param {function} props.onTimezoneChange - The callback function for timezone change. - Optional
+ * @param {ReactNode} props.children - The child components. - Optional
+ * @returns {JSX.Element} The rendered CalProvider component.
+ */
export function CalProvider({
clientId,
accessToken,
diff --git a/packages/platform/atoms/hooks/useMe.ts b/packages/platform/atoms/hooks/useMe.ts
index c0e9f21b5ba..aa861706aaf 100644
--- a/packages/platform/atoms/hooks/useMe.ts
+++ b/packages/platform/atoms/hooks/useMe.ts
@@ -6,6 +6,11 @@ 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 = () => {
const pathname = `/${V2_ENDPOINTS.me}`;
const me = useQuery({
@@ -18,6 +23,7 @@ export const useMe = () => {
throw new Error(res.data.error.message);
});
},
+ enabled: Boolean(http.getAuthorizationHeader()),
});
return me;
diff --git a/packages/platform/atoms/index.ts b/packages/platform/atoms/index.ts
index 67d8fad9ba0..9b32ce542e1 100644
--- a/packages/platform/atoms/index.ts
+++ b/packages/platform/atoms/index.ts
@@ -10,3 +10,4 @@ export { useGetEventTypeById } from "./hooks/event-types/useGetEventTypeById";
export { useCancelBooking } from "./hooks/useCancelBooking";
export { useGetBooking } from "./hooks/useGetBooking";
export { useGetBookings } from "./hooks/useGetBookings";
+export { useMe } from "./hooks/useMe";