diff --git a/apps/x/apps/main/src/auth-server.ts b/apps/x/apps/main/src/auth-server.ts index ad184451..d2be7e82 100644 --- a/apps/x/apps/main/src/auth-server.ts +++ b/apps/x/apps/main/src/auth-server.ts @@ -29,7 +29,7 @@ export function createAuthServer( onCallback: (callbackUrl: URL) => void | Promise ): Promise { return new Promise((resolve, reject) => { - const server = createServer((req, res) => { + const server = createServer(async (req, res) => { if (!req.url) { res.writeHead(400); res.end('Bad Request'); @@ -64,27 +64,51 @@ export function createAuthServer( return; } - // Handle callback - pass full URL so params like iss (OpenID Connect) are preserved for token exchange - onCallback(url); + try { + // Handle callback - pass full URL so params like iss (OpenID Connect) + // are preserved for token exchange. + await onCallback(url); - res.writeHead(200, { 'Content-Type': 'text/html' }); - res.end(` - - - - Authorization Successful - - - -

Authorization Successful

-

You can close this window.

- - - - `); + res.writeHead(200, { 'Content-Type': 'text/html' }); + res.end(` + + + + Authorization Successful + + + +

Authorization Successful

+

You can close this window.

+ + + + `); + } catch (callbackError) { + const message = callbackError instanceof Error ? callbackError.message : String(callbackError); + res.writeHead(200, { 'Content-Type': 'text/html' }); + res.end(` + + + + OAuth Error + + + +

Authorization Failed

+

Error: ${escapeHtml(message)}

+

You can close this window.

+ + + + `); + } } else { res.writeHead(404); res.end('Not Found'); @@ -104,4 +128,3 @@ export function createAuthServer( }); }); } -