Skip to content

The open alternative to Salesforce, designed for AI.

feat(sdk): confirm authentication method on remote add (#19947)

Félix Malfaitc2cf3eac50a0
diff --git a/packages/twenty-sdk/src/cli/commands/remote.ts b/packages/twenty-sdk/src/cli/commands/remote.ts
index ef41b49d60d..fbf2c9fcdb1 100644
--- a/packages/twenty-sdk/src/cli/commands/remote.ts
+++ b/packages/twenty-sdk/src/cli/commands/remote.ts
@@ -18,20 +18,29 @@ const deriveRemoteName = (url: string): string => {
}
};
-const authenticate = async (apiUrl: string, apiKey?: string): Promise<void> => {
- const result = apiKey
- ? await authLogin({ apiKey, apiUrl })
- : await runOAuthWithApiKeyFallback(apiUrl);
+type AuthMethod = 'OAuth' | 'API key';
- if (!result.success) {
- console.error(chalk.red('✗ Authentication failed.'));
- process.exit(1);
+const authenticate = async (
+ apiUrl: string,
+ apiKey?: string,
+): Promise<AuthMethod> => {
+ if (apiKey) {
+ const result = await authLogin({ apiKey, apiUrl });
+
+ if (!result.success) {
+ console.error(chalk.red('✗ Authentication failed.'));
+ process.exit(1);
+ }
+
+ return 'API key';
}
+
+ return runOAuthWithApiKeyFallback(apiUrl);
};
const runOAuthWithApiKeyFallback = async (
apiUrl: string,
-): Promise<{ success: boolean }> => {
+): Promise<AuthMethod> => {
await inquirer.prompt([
{
type: 'input',
@@ -43,7 +52,7 @@ const runOAuthWithApiKeyFallback = async (
const oauthResult = await authLoginOAuth({ apiUrl });
if (oauthResult.success) {
- return oauthResult;
+ return 'OAuth';
}
console.log(chalk.yellow(oauthResult.error.message));
@@ -58,7 +67,17 @@ const runOAuthWithApiKeyFallback = async (
},
]);
- return authLogin({ apiKey: keyAnswer.apiKey, apiUrl });
+ const fallbackResult = await authLogin({
+ apiKey: keyAnswer.apiKey,
+ apiUrl,
+ });
+
+ if (!fallbackResult.success) {
+ console.error(chalk.red('✗ Authentication failed.'));
+ process.exit(1);
+ }
+
+ return 'API key';
};
export const registerRemoteCommands = (program: Command): void => {
@@ -92,7 +111,11 @@ export const registerRemoteCommands = (program: Command): void => {
const config = await configService.getConfigForRemote(options.as);
ConfigService.setActiveRemote(options.as);
- await authenticate(config.apiUrl, options.apiKey);
+ const method = await authenticate(config.apiUrl, options.apiKey);
+
+ console.log(
+ chalk.green(`✓ Re-authenticated "${options.as}" via ${method}.`),
+ );
await configService.setDefaultRemote(options.as);
console.log(chalk.green(`✓ Default remote set to "${options.as}".`));
@@ -143,7 +166,11 @@ export const registerRemoteCommands = (program: Command): void => {
const name = options.as ?? deriveRemoteName(apiUrl);
ConfigService.setActiveRemote(name);
- await authenticate(apiUrl, options.apiKey);
+ const method = await authenticate(apiUrl, options.apiKey);
+
+ console.log(
+ chalk.green(`✓ Remote "${name}" added (${apiUrl}) via ${method}.`),
+ );
await configService.setDefaultRemote(name);
console.log(chalk.green(`✓ Default remote set to "${name}".`));