Skip to content

Commit

Permalink
fix(sync): verifyOwnership not awaited (#1952)
Browse files Browse the repository at this point in the history
## Describe your changes

Fixes NAN-690

- Correctly await verifyOwnership
- Add missing return after response code
- Reuse activityLogId
  • Loading branch information
bodinsamuel authored Apr 4, 2024
1 parent 6ef0840 commit 05ab9cc
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions packages/server/lib/controllers/sync.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import {
SyncClient,
updateScheduleStatus,
updateSuccess as updateSuccessActivityLog,
createActivityLogAndLogMessage,
createActivityLogMessageAndEnd,
createActivityLog,
getAndReconcileDifferences,
Expand Down Expand Up @@ -44,7 +43,8 @@ import {
getEnvironmentAndAccountId,
getSyncAndActionConfigsBySyncNameAndConfigId,
isOk,
isErr
isErr,
createActivityLogMessage
} from '@nangohq/shared';

class SyncController {
Expand Down Expand Up @@ -614,20 +614,21 @@ class SyncController {
environment_id: environment.id,
operation_name: sync_name
};
const activityLogId = await createActivityLog(log);

if (!verifyOwnership(nango_connection_id, environment.id, sync_id)) {
await createActivityLogAndLogMessage(log, {
if (!(await verifyOwnership(nango_connection_id, environment.id, sync_id))) {
await createActivityLogMessage({
level: 'error',
activity_log_id: activityLogId!,
environment_id: environment.id,
timestamp: Date.now(),
content: `Unauthorized access to run the command: "${action}" for sync: ${sync_id}`
});

res.sendStatus(401);
return;
}

const activityLogId = await createActivityLog(log);

const syncClient = await SyncClient.getInstance();

if (!syncClient) {
Expand Down

0 comments on commit 05ab9cc

Please sign in to comment.