From 526e843beb18e1b6480c5131e2a7049a258a1e11 Mon Sep 17 00:00:00 2001 From: Jadoothespitz Date: Wed, 8 Apr 2026 22:58:03 +0900 Subject: [PATCH] fix: use WSL2 host IP for OAuth callback instead of 127.0.0.1 --- cli/src/lib/auth.js | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/cli/src/lib/auth.js b/cli/src/lib/auth.js index 2c386ea..32e855d 100644 --- a/cli/src/lib/auth.js +++ b/cli/src/lib/auth.js @@ -11,7 +11,20 @@ const AUTH_ENDPOINT = `${CLERK_ISSUER}/oauth/authorize`; const TOKEN_ENDPOINT = `${CLERK_ISSUER}/oauth/token`; const REGISTER_ENDPOINT = `${CLERK_ISSUER}/oauth/register`; const CALLBACK_PORT = 9876; -const REDIRECT_URI = `http://127.0.0.1:${CALLBACK_PORT}/callback`; + +function getListenHost() { + try { + const version = readFileSync('/proc/version', 'utf8').toLowerCase(); + if (version.includes('microsoft')) { + return execSync('hostname -I').toString().trim().split(' ')[0]; + } + } catch {} + return '127.0.0.1'; +} + +const LISTEN_HOST = getListenHost(); + +const REDIRECT_URI = `http://${LISTEN_HOST}:${CALLBACK_PORT}/callback`; const USERINFO_ENDPOINT = `${CLERK_ISSUER}/oauth/userinfo`; const SCOPES = 'profile email offline_access'; @@ -127,7 +140,7 @@ function startCallbackServer() { } }); - server.listen(CALLBACK_PORT, '127.0.0.1', () => { + server.listen(CALLBACK_PORT, LISTEN_HOST, () => { resolve(server); }); }); @@ -141,7 +154,7 @@ function waitForCallback(server) { }, 120000); server.on('request', (req, res) => { - const url = new URL(req.url, `http://127.0.0.1:${CALLBACK_PORT}`); + const url = new URL(req.url, `http://${LISTEN_HOST}:${CALLBACK_PORT}`); if (url.pathname !== '/callback') { res.writeHead(404);