Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 16 additions & 7 deletions src/modules/integration-picker/hooks/useIntegrationPicker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -536,7 +536,9 @@ export const useIntegrationPicker = ({
const poll = async () => {
if (!pollingIntervalRef.current) return;

const result = await pollConnectionAttempt(baseUrl, attemptId).catch(() => null);
const result = await pollConnectionAttempt(baseUrl, token, attemptId).catch(
() => null,
);

if (!result) {
if (debugRef.current) {
Expand All @@ -554,6 +556,13 @@ export const useIntegrationPicker = ({
oauthResolvedRef.current = true;
teardownOAuth();
handleSuccess({ id: result.account.id, provider });
parent.postMessage(
{
type: EventType.AccountConnected,
account: { id: result.account.id, provider },
},
'*',
Comment on lines +559 to +564
);
} else if (result.status === 'error') {
oauthResolvedRef.current = true;
teardownOAuth();
Expand All @@ -575,7 +584,7 @@ export const useIntegrationPicker = ({

pollingIntervalRef.current = window.setTimeout(poll, 2000);
},
[baseUrl, teardownOAuth, handleSuccess],
[baseUrl, token, teardownOAuth, handleSuccess],
);

const startPopupWatcher = useCallback(() => {
Expand Down Expand Up @@ -608,15 +617,15 @@ export const useIntegrationPicker = ({
const connectionAttemptId = connectionAttemptIdRef.current;
teardownOAuth();
if (connectionAttemptId) {
void cancelConnectionAttempt(baseUrl, connectionAttemptId);
void cancelConnectionAttempt(baseUrl, token, connectionAttemptId);
}
if (debugRef.current) {
console.debug('[hub] popup closed, resetting state');
}
setConnectionState({ loading: false, success: false });
};
checkStateTimeoutRef.current = window.setTimeout(check, 1000);
}, [processMessageCallback, teardownOAuth, baseUrl]);
}, [processMessageCallback, teardownOAuth, baseUrl, token]);

const handleConnect = useCallback(async () => {
if (!selectedIntegration) {
Expand Down Expand Up @@ -726,7 +735,7 @@ export const useIntegrationPicker = ({
}
teardownOAuth();
if (attemptId) {
void cancelConnectionAttempt(baseUrl, attemptId);
void cancelConnectionAttempt(baseUrl, token, attemptId);
}
setConnectionState({
loading: false,
Expand Down Expand Up @@ -842,9 +851,9 @@ export const useIntegrationPicker = ({
teardownOAuth();
setConnectionState({ loading: false, success: false });
if (attemptId) {
void cancelConnectionAttempt(baseUrl, attemptId);
void cancelConnectionAttempt(baseUrl, token, attemptId);
}
}, [baseUrl, teardownOAuth]);
}, [baseUrl, token, teardownOAuth]);

const isLoading = isLoadingHubData || isLoadingConnectorData || isLoadingAccountData;
const hasError = !!(errorHubData || errorConnectorData || errorAccountData);
Expand Down
10 changes: 5 additions & 5 deletions src/modules/integration-picker/queries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,21 +111,21 @@ export interface ConnectionAttemptResult {
export const createConnectionAttempt = async (baseUrl: string, token: string) => {
return await postRequest<{ id: string }>({
url: `${baseUrl}/hub/connection_attempts`,
headers: { 'Content-Type': 'application/json' },
headers: { 'Content-Type': 'application/json', 'x-hub-session-token': token },
body: { token },
});
};

export const pollConnectionAttempt = async (baseUrl: string, id: string) => {
export const pollConnectionAttempt = async (baseUrl: string, token: string, id: string) => {
return await getRequest<ConnectionAttemptResult>({
url: `${baseUrl}/hub/connection_attempts/${id}`,
headers: { 'Content-Type': 'application/json' },
headers: { 'Content-Type': 'application/json', 'x-hub-session-token': token },
});
};

export const cancelConnectionAttempt = async (baseUrl: string, id: string) => {
export const cancelConnectionAttempt = async (baseUrl: string, token: string, id: string) => {
return await deleteRequest<void>({
url: `${baseUrl}/hub/connection_attempts/${id}`,
headers: { 'Content-Type': 'application/json' },
headers: { 'Content-Type': 'application/json', 'x-hub-session-token': token },
});
};
Loading