Skip to content

πŸ“¨ The ultimate agentic social media scheduling tool πŸ€–

fix(integrations): re-adding an already connected page kept the old login's refresh token

Gilad Resisie3f6c4a3b625
diff --git a/libraries/nestjs-libraries/src/database/prisma/integrations/integration.repository.ts b/libraries/nestjs-libraries/src/database/prisma/integrations/integration.repository.ts
index 42d402ff0..0201a18a9 100644
--- a/libraries/nestjs-libraries/src/database/prisma/integrations/integration.repository.ts
+++ b/libraries/nestjs-libraries/src/database/prisma/integrations/integration.repository.ts
@@ -181,6 +181,20 @@ export class IntegrationRepository {
},
});
+ // The page was picked through a fresh login: the row that keeps living
+ // must also take that login's identity and refresh token, otherwise the
+ // next refresh runs as the old identity and cannot find the page.
+ const fresh = existing
+ ? await this._integration.model.integration.findUnique({
+ where: { id },
+ select: {
+ rootInternalId: true,
+ refreshToken: true,
+ tokenExpiration: true,
+ },
+ })
+ : null;
+
if (existing) {
await this._posts.model.post.updateMany({
where: {
@@ -208,8 +222,16 @@ export class IntegrationRepository {
},
data: {
...params,
+ ...(fresh?.rootInternalId
+ ? { rootInternalId: fresh.rootInternalId }
+ : {}),
+ ...(fresh?.refreshToken ? { refreshToken: fresh.refreshToken } : {}),
+ ...(fresh?.tokenExpiration
+ ? { tokenExpiration: fresh.tokenExpiration }
+ : {}),
disabled: false,
deletedAt: null,
+ refreshNeeded: false,
},
});
}