tao-shen Claude Opus 4.6 commited on
Commit
9a23aad
·
1 Parent(s): 1fc4864

fix: use server-side URL rewrite instead of 302 redirect for token injection

Browse files

302 redirect was unreliable in incognito mode — the browser followed
the redirect but OpenClaw's frontend sometimes failed to pick up the
token. Server-side rewrite injects the token directly into req.url
before OpenClaw processes it, eliminating the redirect round-trip.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

Files changed (1) hide show
  1. scripts/token-redirect.cjs +3 -4
scripts/token-redirect.cjs CHANGED
@@ -215,12 +215,11 @@ http.Server.prototype.emit = function (event, ...args) {
215
  return origEmit.apply(this, [event, ...args]);
216
  }
217
  } else {
218
- // Default mode: redirect GET / to /?token=xxx
219
  if (req.method === 'GET' && !req.headers.upgrade) {
220
  if (pathname === '/' && !parsed.query.token) {
221
- res.writeHead(302, { Location: `/?token=${GATEWAY_TOKEN}` });
222
- res.end();
223
- return true;
224
  }
225
  }
226
  }
 
215
  return origEmit.apply(this, [event, ...args]);
216
  }
217
  } else {
218
+ // Default mode: rewrite URL to inject token (no redirect needed)
219
  if (req.method === 'GET' && !req.headers.upgrade) {
220
  if (pathname === '/' && !parsed.query.token) {
221
+ req.url = `/?token=${GATEWAY_TOKEN}`;
222
+ return origEmit.apply(this, [event, ...args]);
 
223
  }
224
  }
225
  }