Skip to content

fix: use segmentId instead of tenantId to get linkedIn tokens from nango [CM-335] #3173

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 18, 2025
Merged
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
3 changes: 2 additions & 1 deletion backend/src/api/integration/helpers/linkedinConnect.ts
Original file line number Diff line number Diff line change
@@ -4,6 +4,7 @@ import PermissionChecker from '../../../services/user/permissionChecker'

export default async (req, res) => {
new PermissionChecker(req).validateHas(Permissions.values.tenantEdit)
const payload = await new IntegrationService(req).linkedinConnect()
const segmentId = req.body.segments[0]
const payload = await new IntegrationService(req).linkedinConnect(segmentId)
await req.responseHandler.success(req, res, payload)
}
3 changes: 2 additions & 1 deletion backend/src/api/integration/helpers/redditOnboard.ts
Original file line number Diff line number Diff line change
@@ -4,6 +4,7 @@ import PermissionChecker from '../../../services/user/permissionChecker'

export default async (req, res) => {
new PermissionChecker(req).validateHas(Permissions.values.tenantEdit)
const payload = await new IntegrationService(req).redditOnboard(req.body.subreddits)
const segmentId = req.body.segments[0]
const payload = await new IntegrationService(req).redditOnboard(req.body.subreddits, segmentId)
await req.responseHandler.success(req, res, payload)
}
19 changes: 12 additions & 7 deletions backend/src/services/integrationService.ts
Original file line number Diff line number Diff line change
@@ -5,7 +5,7 @@ import axios, { AxiosRequestConfig, AxiosResponse } from 'axios'
import lodash from 'lodash'
import moment from 'moment'

import { DEFAULT_TENANT_ID, EDITION, Error400, Error404, Error542 } from '@crowd/common'
import { EDITION, Error400, Error404, Error542 } from '@crowd/common'
import {
NangoIntegration,
connectNangoIntegration,
@@ -846,10 +846,10 @@ export default class IntegrationService {
throw new Error404(this.options.language, 'errors.linkedin.cantOnboardWrongStatus')
}

async linkedinConnect() {
const nangoId = `${DEFAULT_TENANT_ID}-${PlatformType.LINKEDIN}`

async linkedinConnect(segmentId: string) {
const nangoId = `${segmentId}-${PlatformType.LINKEDIN}`
let token: string

try {
token = await getToken(nangoId, PlatformType.LINKEDIN, this.options.log)
} catch (err) {
@@ -888,7 +888,7 @@ export default class IntegrationService {
integration = await this.createOrUpdate(
{
platform: PlatformType.LINKEDIN,
settings: { organizations, updateMemberAttributes: true },
settings: { organizations, updateMemberAttributes: true, nangoId },
status,
},
transaction,
@@ -912,7 +912,7 @@ export default class IntegrationService {
* @param subreddits Subreddits to track
* @returns integration object
*/
async redditOnboard(subreddits) {
async redditOnboard(subreddits, segmentId) {
const transaction = await SequelizeRepository.createTransaction(this.options)

let integration
@@ -922,7 +922,11 @@ export default class IntegrationService {
integration = await this.createOrUpdate(
{
platform: PlatformType.REDDIT,
settings: { subreddits, updateMemberAttributes: true },
settings: {
subreddits,
updateMemberAttributes: true,
nangoId: `${segmentId}-${PlatformType.REDDIT}`,
},
status: 'in-progress',
},
transaction,
@@ -1311,6 +1315,7 @@ export default class IntegrationService {
tags: integrationData.tags,
keywords: integrationData.keywords,
updateMemberAttributes: true,
nangoId: `${integrationData.segments[0]}-${PlatformType.STACKOVERFLOW}`,
},
status: 'in-progress',
},
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { DEFAULT_TENANT_ID, singleOrDefault } from '@crowd/common'
import { singleOrDefault } from '@crowd/common'
import {
IntegrationRunWorkerEmitter,
IntegrationStreamWorkerEmitter,
@@ -295,13 +295,14 @@ export default class IntegrationRunService extends LoggerBase {
const cache = new RedisCache(`int-${runInfo.integrationType}`, this.redisClient, this.log)

const nangoConfig = NANGO_CONFIG()

// eslint-disable-next-line @typescript-eslint/no-explicit-any
const nangoId = (runInfo.integrationSettings as any)?.nangoId
const context: IGenerateStreamsContext = {
onboarding: runInfo.onboarding,
serviceSettings: {
nangoUrl: nangoConfig.url,
nangoSecretKey: nangoConfig.secretKey,
nangoId: `${DEFAULT_TENANT_ID}-${runInfo.integrationType}`,
nangoId: nangoId,
},
platformSettings: PLATFORM_CONFIG(runInfo.integrationType),
integration: {
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { DEFAULT_TENANT_ID, addSeconds, singleOrDefault } from '@crowd/common'
import { addSeconds, singleOrDefault } from '@crowd/common'
import {
DataSinkWorkerEmitter,
IntegrationRunWorkerEmitter,
@@ -284,12 +284,13 @@ export default class IntegrationStreamService extends LoggerBase {
)

const nangoConfig = NANGO_CONFIG()

// eslint-disable-next-line @typescript-eslint/no-explicit-any
const nangoId = (streamInfo.integrationSettings as any)?.nangoId
const context: IProcessWebhookStreamContext = {
serviceSettings: {
nangoUrl: nangoConfig.url,
nangoSecretKey: nangoConfig.secretKey,
nangoId: `${DEFAULT_TENANT_ID}-${streamInfo.integrationType}`,
nangoId: nangoId,
},

platformSettings: PLATFORM_CONFIG(streamInfo.integrationType),
@@ -447,13 +448,14 @@ export default class IntegrationStreamService extends LoggerBase {
)

const nangoConfig = NANGO_CONFIG()

// eslint-disable-next-line @typescript-eslint/no-explicit-any
const nangoId = (streamInfo.integrationSettings as any)?.nangoId
const context: IProcessStreamContext = {
onboarding: streamInfo.onboarding,
serviceSettings: {
nangoUrl: nangoConfig.url,
nangoSecretKey: nangoConfig.secretKey,
nangoId: `${DEFAULT_TENANT_ID}-${streamInfo.integrationType}`,
nangoId: nangoId,
},

platformSettings: PLATFORM_CONFIG(streamInfo.integrationType),
Loading
Oops, something went wrong.