Skip to content

Commit f15e891

Browse files
Fix: correctly pass query params into /templates infra openapi-fetch (#77)
This pr fixes correct invocation of `/templates` infra route to get the correct templates based on the `teamID`. Previously the query param for `teamID` was passed outside the `params` prop, which made it look like the query params are passed correctly, but actually they were not applied to the final invocation url. This resulted in the templates still being returned, but the team for which the templates are returned was arbitrarily chosen, based on the user details inferred from the access token. As a result, users of the dashboard saw the same templates, regardless of their selected team. This issue was tricky to spot, since the infra route for `/templates` accepts this param as nullable and does not throw, but rather return the templates for an arbitrary team. Additionally this pr: - improves the openapi-fetch client definition to explicitly use next.js's version of fetch instead of globalThis.fetch - next.js fetch logging by default, which makes issues like these easier to spot in development - improves the `VERBOSE` flag condition, for being able to turn of verbose logging in development environments
1 parent 3cb0e60 commit f15e891

File tree

5 files changed

+17
-10
lines changed

5 files changed

+17
-10
lines changed

next.config.mjs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,11 @@ const config = {
1717
bodySizeLimit: '5mb',
1818
},
1919
},
20+
logging: {
21+
fetches: {
22+
fullUrl: true,
23+
},
24+
},
2025
trailingSlash: false,
2126
headers: async () => [
2227
{

src/configs/flags.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
11
export const ALLOW_SEO_INDEXING = process.env.ALLOW_SEO_INDEXING === '1'
2-
export const VERBOSE =
3-
process.env.NODE_ENV === 'development' ||
4-
process.env.NEXT_PUBLIC_VERBOSE === '1'
2+
export const VERBOSE = process.env.NEXT_PUBLIC_VERBOSE === '1'
53
export const INCLUDE_BILLING = process.env.NEXT_PUBLIC_INCLUDE_BILLING === '1'

src/lib/clients/api.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,12 @@ import type { paths as InfraPaths } from '@/types/infra-api'
33

44
export const infra = createClient<InfraPaths>({
55
baseUrl: process.env.INFRA_API_URL,
6-
headers: {
7-
'Content-Type': 'application/json',
6+
fetch: ({ url, headers, body, method, ...options }) => {
7+
return fetch(url, {
8+
headers,
9+
body,
10+
method,
11+
...options,
12+
})
813
},
914
})

src/server/sandboxes/get-team-sandboxes.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,6 @@ export const getTeamSandboxes = authActionClient
3333
}
3434

3535
const res = await infra.GET('/sandboxes', {
36-
query: {
37-
state: 'running',
38-
},
3936
headers: {
4037
...SUPABASE_AUTH_HEADERS(session.access_token, teamId),
4138
},

src/server/templates/get-team-templates.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,10 @@ export const getTeamTemplates = authActionClient
3333
}
3434

3535
const res = await infra.GET('/templates', {
36-
query: {
37-
teamID: teamId,
36+
params: {
37+
query: {
38+
teamID: teamId,
39+
},
3840
},
3941
headers: {
4042
...SUPABASE_AUTH_HEADERS(session.access_token),

0 commit comments

Comments
 (0)