Skip to content

Commit

Permalink
Try preferAuth on search-markets
Browse files Browse the repository at this point in the history
  • Loading branch information
IanPhilips committed Dec 2, 2024
1 parent 4a3e9ce commit 2823f6a
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
3 changes: 3 additions & 0 deletions common/src/api/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,8 @@ type APIGenericSchema = {
returns?: Record<string, any>
// 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 }
Expand Down Expand Up @@ -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,
Expand Down
6 changes: 4 additions & 2 deletions web/lib/api/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,10 @@ export async function api<P extends APIPath>(
path: P,
params: APIParams<P> = {}
) {
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++
Expand All @@ -41,7 +43,7 @@ export async function api<P extends APIPath>(

return (await call(
formatApiUrlWithParams(path, params),
API[path].method,
pathProps.method,
params
)) as Promise<APIResponse<P>>
}
Expand Down

0 comments on commit 2823f6a

Please sign in to comment.