Skip to content

Commit

Permalink
Fix frontend code snippet (self-hosted) (NangoHQ#583)
Browse files Browse the repository at this point in the history
  • Loading branch information
bastienbeurier authored Apr 25, 2023
1 parent 5901971 commit ca77fba
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 4 deletions.
4 changes: 3 additions & 1 deletion packages/server/lib/controllers/account.controller.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { Request, Response, NextFunction } from 'express';
import accountService from '../services/account.service.js';
import { getUserAndAccountFromSession, isCloud, getOauthCallbackUrl } from '../utils/utils.js';
import { getUserAndAccountFromSession, isCloud, getOauthCallbackUrl, getBaseUrl } from '../utils/utils.js';
import errorManager from '../utils/error.manager.js';

class AccountController {
Expand All @@ -13,6 +13,8 @@ class AccountController {
account.secret_key = process.env['NANGO_SECRET_KEY'] || '(none)';
}

account.host = getBaseUrl();

res.status(200).send({ account: account });
} catch (err) {
next(err);
Expand Down
1 change: 1 addition & 0 deletions packages/server/lib/models.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ export interface Account {
owner_id: number | undefined;
secret_key_iv?: string | null;
secret_key_tag?: string | null;
host?: string | null;
}

export interface User {
Expand Down
8 changes: 5 additions & 3 deletions packages/webapp/src/pages/ConnectionCreate.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ export default function IntegrationCreate() {
const [connectionId, setConnectionId] = useState<string>('test-connection-id');
const [connectionConfigParams, setConnectionConfigParams] = useState<Record<string, string> | null>(null);
const [publicKey, setPublicKey] = useState('');
const [hostUrl, setHostUrl] = useState('');
const getIntegrationListAPI = useGetIntegrationListAPI();
const getProjectInfoAPI = useGetProjectInfoAPI();
const analyticsTrack = useAnalyticsTrack();
Expand Down Expand Up @@ -59,6 +60,7 @@ export default function IntegrationCreate() {
if (res?.status === 200) {
const account = (await res.json())['account'];
setPublicKey(account.public_key);
setHostUrl(account.host || baseUrl());
}
};

Expand All @@ -79,7 +81,7 @@ export default function IntegrationCreate() {
connection_config_params: { value: string };
};

let nango = new Nango({ host: baseUrl(), publicKey: isCloud() ? publicKey : undefined });
let nango = new Nango({ host: hostUrl, publicKey: isCloud() ? publicKey : undefined });

nango
.auth(target.integration_unique_key.value, target.connection_id.value, { params: connectionConfigParams || {} })
Expand Down Expand Up @@ -134,7 +136,7 @@ export default function IntegrationCreate() {
let args = [];

if (isStaging() || isHosted()) {
args.push(`host: '${baseUrl()}'`);
args.push(`host: '${hostUrl}'`);
}

if (isCloud() && publicKey) {
Expand Down Expand Up @@ -169,7 +171,7 @@ nango.auth('${integration?.uniqueKey}', '${connectionId}'${connectionConfigStr})

return (
<DashboardLayout selectedItem={LeftNavBarItems.Integrations}>
{integrations && !!integrations.length && (!isCloud() || publicKey) && (
{integrations && !!integrations.length && publicKey && hostUrl && (
<div className="mx-auto w-largebox pb-40">
<h2 className="mx-20 mt-16 text-left text-3xl font-semibold tracking-tight text-white mb-12">Add New Connection</h2>
<div className="mx-20 h-fit border border-border-gray rounded-md text-white text-sm py-14 px-8">
Expand Down

0 comments on commit ca77fba

Please sign in to comment.