diff --git a/web/apps/accounts/src/services/passkey.ts b/web/apps/accounts/src/services/passkey.ts index b30155e483..859dd9abf7 100644 --- a/web/apps/accounts/src/services/passkey.ts +++ b/web/apps/accounts/src/services/passkey.ts @@ -1,5 +1,5 @@ import { isDevBuild } from "@/next/env"; -import { apiOrigin } from "@/next/origins"; +import { apiOrigin, apiURL } from "@/next/origins"; import { clientPackageName } from "@/next/types/app"; import { TwoFactorAuthorizationResponse } from "@/next/types/credentials"; import { ensure } from "@/utils/ensure"; @@ -58,7 +58,7 @@ const GetPasskeysResponse = z.object({ * has no passkeys. */ export const getPasskeys = async (token: string) => { - const url = `${apiOrigin()}/passkeys`; + const url = await apiURL("passkeys"); const res = await fetch(url, { headers: accountsAuthenticatedRequestHeaders(token), }); diff --git a/web/packages/next/origins.ts b/web/packages/next/origins.ts index b21dbd59a6..45b8149890 100644 --- a/web/packages/next/origins.ts +++ b/web/packages/next/origins.ts @@ -11,6 +11,19 @@ import { get, set } from "idb-keyval"; export const apiOrigin = async () => (await customAPIOrigin()) ?? "https://api.ente.io"; +/** + * A convenience function to construct an endpoint in a one-liner. + * + * This avoids us having to create a temporary variable or otherwise complicate + * the call sites since async functions cannot be used inside template literals. + * + * @returns The equivalent of `${await apiOrigin()}/pathEtc` + */ +export const apiURL = async (pathEtc: string) => { + const origin = await apiOrigin(); + return `${origin}/${pathEtc}`; +}; + /** * Return the overridden API origin, if one is defined by either (in priority * order):