From b3ae2481648bc72cd7c9b0d7301daf957ae8f334 Mon Sep 17 00:00:00 2001 From: Chirag Aggarwal Date: Wed, 8 Jul 2026 15:49:36 +0530 Subject: [PATCH] (refactor): drop the anonymous PAR client now that /par allows credentialed platform origins --- .../(public)/oauth2/consent/+page.svelte | 21 ++++--------------- 1 file changed, 4 insertions(+), 17 deletions(-) diff --git a/src/routes/(public)/oauth2/consent/+page.svelte b/src/routes/(public)/oauth2/consent/+page.svelte index 68c8549bb..c5c0dc4d1 100644 --- a/src/routes/(public)/oauth2/consent/+page.svelte +++ b/src/routes/(public)/oauth2/consent/+page.svelte @@ -2,7 +2,7 @@ import { goto } from '$app/navigation'; import { base } from '$app/paths'; import { page } from '$app/state'; - import { AppwriteException, Client, Oauth2, type Models } from '@appwrite.io/console'; + import { AppwriteException, type Models } from '@appwrite.io/console'; import { Card, Layout, Typography, Icon, Spinner } from '@appwrite.io/pink-svelte'; import { IconExclamation } from '@appwrite.io/pink-icons-svelte'; import { Button } from '$lib/elements/forms'; @@ -33,19 +33,6 @@ phase = outcome === 'approved' ? 'approved' : 'denied'; } - // /par is public (no auth needed), which is exactly why the default client - // can't call it: public endpoints are served like /token — wildcard CORS - // with Access-Control-Allow-Credentials: false — and the browser blocks - // sdk.forConsole's credentialed (cookie-sending) fetch against that. This - // client sends the same request with credentials omitted. - function anonymousOAuth2(): Oauth2 { - const client = new Client() - .setEndpoint(sdk.forConsole.client.config.endpoint) - .setProject('console') - .setCredentials('omit'); - return new Oauth2(client); - } - // A $derived string so identity-only replacements of page.url (e.g. login // calling invalidate(ACCOUNT) right after goto) don't restart the flow — // a restart would cancel an in-flight authorize and re-dereference an @@ -160,8 +147,8 @@ if (cancelled) return; if (!loggedInAccount) { - // The handle is single-use: never dereference it while logged - // out — the server consumes it before rejecting the call. + // Dereferencing while logged out can only 401; keep the + // single-use handle untouched and go straight to login. goSignIn(); return; } @@ -203,7 +190,7 @@ // during GitHub sign-in and can exceed its size limits. const resources = params.getAll('resource'); try { - const par = await anonymousOAuth2().createPAR({ + const par = await sdk.forConsole.oauth2.createPAR({ clientId, redirectUri: params.get('redirect_uri') ?? '', responseType: params.get('response_type') ?? 'code',