mirror of
https://github.com/Azure/cosmos-explorer.git
synced 2026-01-24 12:14:17 +00:00
* Default to new backend endpoint if the endpoint in current context does not match existing set in constants. * Remove some env references. * Added comments with reasoning for selecting new backend by default. * Update comment. * Remove all references to useNewPortalBackendEndpoint now that old backend is disabled in all environments. * Resolve lint issues. * Removed references to old backend from Cassandra and Mongo Apis * fix unit tests --------- Co-authored-by: Asier Isayas <aisayas@microsoft.com>
31 lines
1.1 KiB
TypeScript
31 lines
1.1 KiB
TypeScript
import { useEffect, useState } from "react";
|
|
import { HttpHeaders } from "../Common/Constants";
|
|
import { configContext } from "../ConfigContext";
|
|
import { AccessInputMetadata } from "../Contracts/DataModels";
|
|
|
|
export async function fetchAccessData(portalToken: string): Promise<AccessInputMetadata> {
|
|
const headers = new Headers();
|
|
// Portal encrypted token API quirk: The token header must be URL encoded
|
|
headers.append(HttpHeaders.guestAccessToken, encodeURIComponent(portalToken));
|
|
const url: string = `${configContext.PORTAL_BACKEND_ENDPOINT}/api/connectionstring/runtimeproxy/accessinputmetadata`;
|
|
const options = {
|
|
method: "GET",
|
|
headers: headers,
|
|
};
|
|
|
|
return fetch(url, options)
|
|
.then((response) => response.json())
|
|
.catch((error) => console.error(error));
|
|
}
|
|
|
|
export function useTokenMetadata(token: string): AccessInputMetadata | undefined {
|
|
const [state, setState] = useState<AccessInputMetadata | undefined>();
|
|
|
|
useEffect(() => {
|
|
if (token) {
|
|
fetchAccessData(token).then((response) => setState(response));
|
|
}
|
|
}, [token]);
|
|
return state;
|
|
}
|