fix: only call useMe if access token is set (#14576)
* fix: only call useMe if access token is set * chore: export use me hook
This commit is contained in:
@@ -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,
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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";
|
||||
|
||||
Reference in New Issue
Block a user