diff --git a/gateway/src/routes/oidc/authorize.ts b/gateway/src/routes/oidc/authorize.ts
index 891a01e..75d81ba 100644
--- a/gateway/src/routes/oidc/authorize.ts
+++ b/gateway/src/routes/oidc/authorize.ts
@@ -19,6 +19,115 @@ export function createAuthorizeRouter(
): Router {
const router = Router();
+ function renderLoginPage(clientName: string, authCode: string, state: string, errorMessage?: string): string {
+ const errorHtml = errorMessage
+ ? `
${errorMessage}
`
+ : '';
+ return `
+
+
+
+
+
+ Sign in - ATAuth
+
+
+
+
+
🔒
+
Sign in with ATAuth
+
Use your Bluesky or AT Protocol identity
+
Signing in to ${clientName}
+ ${errorHtml}
+
+
+
+
+`;
+ }
+
/**
* GET/POST /oauth/authorize
* Start the authorization flow
@@ -152,194 +261,7 @@ export function createAuthorizeRouter(
});
// Show login page asking for handle
- const loginPageHtml = `
-
-
-
-
-
- Sign in - ATAuth
-
-
-
-
-
🔐
-
Sign in with ATAuth
-
Use your Bluesky or AT Protocol identity
-
-
- Signing in to ${client.name || client_id}
-
-
-
-
-
-
-
-
-
-`;
-
- res.type('html').send(loginPageHtml);
+ res.type('html').send(renderLoginPage(client.name || client_id, authCode, state || ''));
} catch (error) {
console.error('[OIDC Authorize] Error:', error);
res.status(500).json({
@@ -419,7 +341,12 @@ export function createAuthorizeRouter(
if (isJsonRequest) {
res.status(400).json({ error: userMessage });
} else {
- res.status(400).send(userMessage);
+ // Re-render login page with error for native form submissions
+ const { auth_code: errAuthCode } = req.body;
+ const errAuthData = errAuthCode ? db.getAuthorizationCode(errAuthCode) : null;
+ const errClient = errAuthData ? db.getApp(errAuthData.client_id) : null;
+ const errClientName = errClient?.name || errAuthData?.client_id || 'Unknown';
+ res.status(400).type('html').send(renderLoginPage(errClientName, errAuthCode || '', errAuthData?.state || '', userMessage));
}
}
});