Skip to content

Commit 71b0ecf

Browse files
ktamas77claude
andcommitted
fix(login): accept ?secret= callback param and clarify errors
The web app redirects to the loopback callback with ?secret=<token>&state=<state>, but the GET handler only looked for ?token=, so the token was silently dropped and the user saw a misleading "State mismatch" error. Accept both names, and distinguish a missing/empty payload from an actual state mismatch so future failures are diagnosable from the message alone. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent 0e257d1 commit 71b0ecf

1 file changed

Lines changed: 10 additions & 3 deletions

File tree

src/commands/login.ts

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,13 @@ export async function loginCommand(opts: LoginOptions = {}): Promise<void> {
9999

100100
try {
101101
const payload = await extractPayload(req, url);
102-
if (!payload || payload.state !== state) {
102+
if (!payload) {
103+
fail(res, 'Empty or unrecognized callback payload');
104+
reject(new Error('Empty callback — missing token/secret or state in redirect'));
105+
server.close();
106+
return;
107+
}
108+
if (payload.state !== state) {
103109
fail(res, 'Invalid or missing state');
104110
reject(new Error('State mismatch — login was cancelled or replayed'));
105111
server.close();
@@ -197,9 +203,10 @@ async function extractPayload(req: IncomingMessage, url: URL): Promise<CallbackP
197203
return JSON.parse(body) as CallbackPayload;
198204
}
199205
if (req.method === 'GET') {
200-
// Fallback for GET-style redirects (e.g. ?token=...&state=...).
206+
// Fallback for GET-style redirects. The web app uses `secret=`; older
207+
// builds may use `token=`. Accept either.
201208
const params = url.searchParams;
202-
const token = params.get('token');
209+
const token = params.get('secret') ?? params.get('token');
203210
const state = params.get('state');
204211
if (!token || !state) return null;
205212
return {

0 commit comments

Comments
 (0)