Skip to content

Commit 42da3f2

Browse files
committed
remove open usage from cc auth flow in create magnitude app
1 parent 3f39eac commit 42da3f2

2 files changed

Lines changed: 33 additions & 2 deletions

File tree

.changeset/khaki-plums-invent.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"create-magnitude-app": patch
3+
---
4+
5+
remove 'open' lib usage

packages/create-magnitude-app/src/claudeCode.ts

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ import { homedir } from 'os';
33
import { join, dirname } from 'path';
44
import crypto from 'crypto';
55
import { bold, cyanBright } from 'ansis';
6-
import open from 'open';
76
import { intro, outro, spinner, log, text, select, confirm, isCancel, multiselect } from '@clack/prompts';
7+
import { exec } from 'node:child_process';
88

99
const CLIENT_ID = '9d1c250a-e61b-44d9-88ed-5944d1962f5e';
1010
const CREDS_PATH = join(homedir(), '.magnitude', 'credentials', 'claudeCode.json');
@@ -139,6 +139,32 @@ export async function getValidClaudeCodeAccessToken(): Promise<string | null> {
139139
}
140140
}
141141

142+
function openUrl(url: string): Promise<void> {
143+
return new Promise((resolve, reject) => {
144+
let command: string;
145+
146+
switch (process.platform) {
147+
case 'darwin':
148+
command = `open "${url}"`;
149+
break;
150+
case 'win32':
151+
command = `start "${url}"`;
152+
break;
153+
default:
154+
command = `xdg-open "${url}"`;
155+
break;
156+
}
157+
158+
exec(command, (error) => {
159+
if (error) {
160+
reject(error);
161+
} else {
162+
resolve();
163+
}
164+
});
165+
});
166+
}
167+
142168
export async function completeClaudeCodeAuthFlow(): Promise<string> {
143169
// Try to get existing valid token
144170
const existingToken = await getValidClaudeCodeAccessToken();
@@ -150,7 +176,7 @@ export async function completeClaudeCodeAuthFlow(): Promise<string> {
150176

151177
log.message(cyanBright`Opening browser for authentication...`);
152178
try {
153-
await open(authUrl);
179+
await openUrl(authUrl);
154180
} catch (err) {
155181
log.message('Could not open browser automatically');
156182
}

0 commit comments

Comments
 (0)