-
Notifications
You must be signed in to change notification settings - Fork 25
feat: allow by passing proxy in clerk #2856
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| 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, | ||
|
|
@@ -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 = [ | ||
|
|
@@ -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; | ||
|
Comment on lines
+69
to
+72
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Handle malformed Line 71 parses a backend-provided value with a throwing parser. A bad property value (e.g. whitespace/typo) will throw during render and break this hook. Suggested fix function parseBoolean(value: unknown): boolean {
if (typeof value === "string") {
- return value.toLowerCase() === "true";
+ const normalized = value.trim().toLowerCase();
+ if (normalized === "true") return true;
+ if (normalized === "false") return false;
+ return false;
}
@@
- throw new Error("Invalid boolean value");
+ return false;
}🤖 Prompt for AI AgentsAvoid enabling direct mode before the override property is resolved. Lines 69-72 default to Suggested fix- const { data: proxyDisableProperty } = useQuery({
+ const { data: proxyDisableProperty, isLoading: isProxyDisableLoading } = useQuery({
@@
- const direct =
- proxyDisableProperty && proxyDisableProperty.length > 0
+ const direct =
+ backendUrl && isProxyDisableLoading
+ ? false
+ : proxyDisableProperty && proxyDisableProperty.length > 0
? parseBoolean(proxyDisableProperty[0].value)
: orgDirect;🤖 Prompt for AI Agents |
||
|
|
||
| useEffect(() => { | ||
| // if the organization does not support direct access to the backend, we | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧩 Analysis chain
🏁 Script executed:
cat -n src/hooks/useClerkAttachAuthInterceptorsToAxios.tsx | head -100Repository: flanksource/flanksource-ui
Length of output: 3716
🏁 Script executed:
cat -n src/hooks/useClerkAttachAuthInterceptorsToAxios.tsx | tail -50Repository: flanksource/flanksource-ui
Length of output: 2150
🏁 Script executed:
rg -A 10 "export.*apiBase" --type ts --type tsxRepository: flanksource/flanksource-ui
Length of output: 97
🏁 Script executed:
rg -A 10 "export.*apiBase" --type tsRepository: flanksource/flanksource-ui
Length of output: 527
🏁 Script executed:
rg "queryKey.*properties" --type ts -B 2 -A 5Repository: flanksource/flanksource-ui
Length of output: 2590
🏁 Script executed:
Repository: flanksource/flanksource-ui
Length of output: 52
🏁 Script executed:
Repository: flanksource/flanksource-ui
Length of output: 731
🏁 Script executed:
rg "queryKey.*\[" src/hooks/ReactQuery/Properties.tsx src/api/query-hooks/useFeatureFlags.tsx -A 2 -B 2Repository: flanksource/flanksource-ui
Length of output: 1627
🏁 Script executed:
cat -n src/api/axios.ts | head -50Repository: flanksource/flanksource-ui
Length of output: 1654
🏁 Script executed:
rg "useOrganization\|organization\?.id" src/hooks/useClerkAttachAuthInterceptorsToAxios.tsx -B 2 -A 2Repository: flanksource/flanksource-ui
Length of output: 52
🏁 Script executed:
Repository: flanksource/flanksource-ui
Length of output: 52
🏁 Script executed:
rg "enabled.*backendUrl\|staleTime\|gcTime" src/hooks/useClerkAttachAuthInterceptorsToAxios.tsx -B 3 -A 3Repository: flanksource/flanksource-ui
Length of output: 52
🏁 Script executed:
Repository: flanksource/flanksource-ui
Length of output: 462
Scope the React Query cache key by backend/org context to prevent stale data reuse across org switches.
The static queryKey at line 57 causes React Query to reuse cached
proxy.disabledata from a previous organization when switching orgs, since the queryKey remains unchanged even thoughbackendUrldiffers per organization. With the default 5-minute cache time, this stale data persists.Suggested fix
const { data: proxyDisableProperty } = useQuery({ - queryKey: ["properties", "proxy.disable"], + queryKey: ["properties", organization?.id, backendUrl, "proxy.disable"], queryFn: async () => {📝 Committable suggestion
🤖 Prompt for AI Agents