Co-authored-by: gitstart-calcom <gitstart-calcom@users.noreply.github.com> Co-authored-by: GitStart-Cal.com <121884634+gitstart-calcom@users.noreply.github.com> Co-authored-by: Peer Richelsen <peeroke@gmail.com>
24 lines
914 B
TypeScript
24 lines
914 B
TypeScript
import { APP_CREDENTIAL_SHARING_ENABLED } from "@calcom/lib/constants";
|
|
|
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
const refreshOAuthTokens = async (refreshFunction: () => any, appSlug: string, userId: number | null) => {
|
|
// Check that app syncing is enabled and that the credential belongs to a user
|
|
if (APP_CREDENTIAL_SHARING_ENABLED && process.env.CALCOM_CREDENTIAL_SYNC_ENDPOINT && userId) {
|
|
// Customize the payload based on what your endpoint requires
|
|
// The response should only contain the access token and expiry date
|
|
const response = await fetch(process.env.CALCOM_CREDENTIAL_SYNC_ENDPOINT, {
|
|
method: "POST",
|
|
body: new URLSearchParams({
|
|
calcomUserId: userId.toString(),
|
|
appSlug,
|
|
}),
|
|
});
|
|
return response;
|
|
} else {
|
|
const response = await refreshFunction();
|
|
return response;
|
|
}
|
|
};
|
|
|
|
export default refreshOAuthTokens;
|