Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 25 additions & 3 deletions src/hooks/useClerkAttachAuthInterceptorsToAxios.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { useAuth, useOrganization } from "@clerk/nextjs";
import {
apiBase,
Auth,
CanaryChecker,
Config,
Expand All @@ -11,6 +12,7 @@ import {
Snapshot
} from "@flanksource-ui/api/axios";
import { toastError } from "@flanksource-ui/components/Toast/toast";
import { useQuery } from "@tanstack/react-query";
import { useEffect } from "react";

const allAxiosInstances = [
Expand Down Expand Up @@ -45,9 +47,29 @@ export default function useClerkAttachAuthInterceptorsToAxios() {
// organization set
const backendUrl = organization?.publicMetadata.backend_url as string;

// we need to know if th organization supports direct access to the backend or
// not so we can set the base URL correctly
const direct = parseBoolean(organization?.publicMetadata.direct);
// we need to know if the organization supports direct access to the backend
// or not so we can set the base URL correctly
const orgDirect = parseBoolean(organization?.publicMetadata.direct);

// Fetch the proxy.disable property from backend properties to allow
// toggling direct mode without changing Clerk org metadata
const { data: proxyDisableProperty } = useQuery({
queryKey: ["properties", "proxy.disable"],
queryFn: async () => {
const response = await apiBase.get<{ name: string; value: string }[]>(
"/properties?name=eq.proxy.disable"
);
return response.data;
},
enabled: !!backendUrl
});

// Property overrides org metadata; fall back to org metadata if property
// doesn't exist
const direct =
proxyDisableProperty && proxyDisableProperty.length > 0
? parseBoolean(proxyDisableProperty[0].value)
: orgDirect;

useEffect(() => {
// if the organization does not support direct access to the backend, we
Expand Down
Loading