From 768f44b7c11c5e67e2a7804e4818a803f27e3340 Mon Sep 17 00:00:00 2001 From: Chirag Aggarwal Date: Wed, 8 Jul 2026 16:14:25 +0530 Subject: [PATCH] (refactor): flatten the consent-page flow and extract oauth2 error constants - Hoist the flow out of the 220-line effect into one named function per entry branch (grant_id / request_uri / raw client_id), cancelled via a run counter instead of a closed-over flag. - Dedupe the authorize-request param extraction shared by createPAR and authorize into readAuthorizeParams(), plus getAccount()/fail() helpers. - Move error messages and the oauth2_invalid_request exception type into a colocated errors.ts. - Build navigation targets with resolve() to satisfy svelte/no-navigation-without-resolve. --- .../(public)/oauth2/consent/+page.svelte | 432 +++++++++--------- src/routes/(public)/oauth2/errors.ts | 18 + 2 files changed, 237 insertions(+), 213 deletions(-) create mode 100644 src/routes/(public)/oauth2/errors.ts diff --git a/src/routes/(public)/oauth2/consent/+page.svelte b/src/routes/(public)/oauth2/consent/+page.svelte index c5c0dc4d1..09c308063 100644 --- a/src/routes/(public)/oauth2/consent/+page.svelte +++ b/src/routes/(public)/oauth2/consent/+page.svelte @@ -1,6 +1,6 @@ @@ -286,7 +292,7 @@ {error} - diff --git a/src/routes/(public)/oauth2/errors.ts b/src/routes/(public)/oauth2/errors.ts new file mode 100644 index 000000000..c91075e57 --- /dev/null +++ b/src/routes/(public)/oauth2/errors.ts @@ -0,0 +1,18 @@ +/** + * Exception `type` values returned by the OAuth2 endpoints. The SDK does not + * export these, so they are mirrored here. + */ +export const OAuth2ErrorType = { + /** + * Covers every dead request_uri handle case (expired, consumed, malformed). + */ + INVALID_REQUEST: 'oauth2_invalid_request' +} as const; + +export const OAuth2ErrorMessage = { + AUTHORIZE_FAILED: 'Could not start authorization.', + GRANT_INVALID: 'This authorization request is invalid or has expired.', + HANDLE_EXPIRED: + 'This sign-in request has expired. Return to the application and try connecting again.', + MISSING_REQUEST: 'Missing authorization request. Open this page from an application sign-in.' +} as const;