From 2823f6a3eb8416037c255b5cdc8069c0b7287213 Mon Sep 17 00:00:00 2001 From: Ian Philips Date: Mon, 2 Dec 2024 07:50:58 -0800 Subject: [PATCH] Try preferAuth on search-markets --- common/src/api/schema.ts | 3 +++ web/lib/api/api.ts | 6 ++++-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/common/src/api/schema.ts b/common/src/api/schema.ts index 455a539cd5..3c05b6cbc7 100644 --- a/common/src/api/schema.ts +++ b/common/src/api/schema.ts @@ -84,6 +84,8 @@ type APIGenericSchema = { returns?: Record // Cache-Control header. like, 'max-age=60' cache?: string + // whether the endpoint should prefer authentication even if not required + preferAuth?: boolean } let _apiTypeCheck: { [x: string]: APIGenericSchema } @@ -756,6 +758,7 @@ export const API = (_apiTypeCheck = { method: 'GET', visibility: 'undocumented', authed: false, + preferAuth: true, cache: DEFAULT_CACHE_STRATEGY, returns: [] as Contract[], props: searchProps, diff --git a/web/lib/api/api.ts b/web/lib/api/api.ts index bfa4c09f8d..6818001cc9 100644 --- a/web/lib/api/api.ts +++ b/web/lib/api/api.ts @@ -26,8 +26,10 @@ export async function api

( path: P, params: APIParams

= {} ) { + const pathProps = API[path] + const preferAuth = 'preferAuth' in pathProps && pathProps.preferAuth // If the api is authed and the user is not loaded, wait for the user to load. - if (API[path].authed && !auth.currentUser) { + if ((pathProps.authed || preferAuth) && !auth.currentUser) { let i = 0 while (!auth.currentUser) { i++ @@ -41,7 +43,7 @@ export async function api

( return (await call( formatApiUrlWithParams(path, params), - API[path].method, + pathProps.method, params )) as Promise> }