Skip to content

Commit 3bc4338

Browse files
authored
Merge pull request #2122 from redpanda-data/fix/provide-jwt-token-for-schema-registry
Fixes an issue with JWT token in schema registry
2 parents 84794d0 + 4b40c31 commit 3bc4338

File tree

1 file changed

+39
-22
lines changed

1 file changed

+39
-22
lines changed

frontend/src/react-query/api/schema-registry.tsx

Lines changed: 39 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,10 @@ export const useListSchemasQuery = () => {
2323
return useTanstackQuery<SchemaRegistrySubject[]>({
2424
queryKey: ['schemaRegistry', 'subjects'],
2525
queryFn: async () => {
26-
const response = await config.fetch(`${config.restBasePath}/schema-registry/subjects`, {
26+
const response = await fetch(`${config.restBasePath}/schema-registry/subjects`, {
27+
headers: {
28+
Authorization: `Bearer ${config.jwt}`,
29+
},
2730
method: 'GET',
2831
});
2932

@@ -47,9 +50,10 @@ export const useSchemaModeQuery = () =>
4750
useTanstackQuery<string | null>({
4851
queryKey: ['schemaRegistry', 'mode'],
4952
queryFn: async () => {
50-
const response = await config.fetch(`${config.restBasePath}/schema-registry/mode`, {
53+
const response = await fetch(`${config.restBasePath}/schema-registry/mode`, {
5154
method: 'GET',
5255
headers: {
56+
Authorization: `Bearer ${config.jwt}`,
5357
'Content-Type': 'application/json',
5458
},
5559
});
@@ -72,9 +76,10 @@ export const useSchemaCompatibilityQuery = () =>
7276
useTanstackQuery<string | null>({
7377
queryKey: ['schemaRegistry', 'compatibility'],
7478
queryFn: async () => {
75-
const response = await config.fetch(`${config.restBasePath}/schema-registry/config`, {
79+
const response = await fetch(`${config.restBasePath}/schema-registry/config`, {
7680
method: 'GET',
7781
headers: {
82+
Authorization: `Bearer ${config.jwt}`,
7883
'Content-Type': 'application/json',
7984
},
8085
});
@@ -101,7 +106,9 @@ export const useSchemaDetailsQuery = (subjectName?: string, options?: { enabled?
101106
`${config.restBasePath}/schema-registry/subjects/${encodeURIComponent(subjectName ?? '')}/versions/all`,
102107
{
103108
method: 'GET',
104-
headers: {},
109+
headers: {
110+
Authorization: `Bearer ${config.jwt}`,
111+
},
105112
}
106113
);
107114

@@ -121,9 +128,10 @@ export const useUpdateGlobalCompatibilityMutation = () => {
121128

122129
return useTanstackMutation<SchemaRegistryConfigResponse, Error, SchemaRegistryCompatibilityMode>({
123130
mutationFn: async (mode: SchemaRegistryCompatibilityMode) => {
124-
const response = await config.fetch(`${config.restBasePath}/schema-registry/config`, {
131+
const response = await fetch(`${config.restBasePath}/schema-registry/config`, {
125132
method: 'PUT',
126133
headers: {
134+
Authorization: `Bearer ${config.jwt}`,
127135
'Content-Type': 'application/json',
128136
},
129137
body: JSON.stringify({ compatibility: mode }),
@@ -160,11 +168,13 @@ export const useUpdateSubjectCompatibilityMutation = () => {
160168
>({
161169
mutationFn: async ({ subjectName, mode }) => {
162170
if (mode === 'DEFAULT') {
163-
const response = await config.fetch(
171+
const response = await fetch(
164172
`${config.restBasePath}/schema-registry/config/${encodeURIComponent(subjectName)}`,
165173
{
166174
method: 'DELETE',
167-
headers: {},
175+
headers: {
176+
Authorization: `Bearer ${config.jwt}`,
177+
},
168178
}
169179
);
170180

@@ -176,16 +186,14 @@ export const useUpdateSubjectCompatibilityMutation = () => {
176186
return response.json();
177187
}
178188

179-
const response = await config.fetch(
180-
`${config.restBasePath}/schema-registry/config/${encodeURIComponent(subjectName)}`,
181-
{
182-
method: 'PUT',
183-
headers: {
184-
'Content-Type': 'application/json',
185-
},
186-
body: JSON.stringify({ compatibility: mode }),
187-
}
188-
);
189+
const response = await fetch(`${config.restBasePath}/schema-registry/config/${encodeURIComponent(subjectName)}`, {
190+
method: 'PUT',
191+
headers: {
192+
Authorization: `Bearer ${config.jwt}`,
193+
'Content-Type': 'application/json',
194+
},
195+
body: JSON.stringify({ compatibility: mode }),
196+
});
189197

190198
if (!response.ok) {
191199
const errorText = await response.text();
@@ -238,9 +246,11 @@ export const useSchemaTypesQuery = () =>
238246
useTanstackQuery<string[]>({
239247
queryKey: ['schemaRegistry', 'types'],
240248
queryFn: async () => {
241-
const response = await config.fetch(`${config.restBasePath}/schema-registry/schemas/types`, {
249+
const response = await fetch(`${config.restBasePath}/schema-registry/schemas/types`, {
242250
method: 'GET',
243-
headers: {},
251+
headers: {
252+
Authorization: `Bearer ${config.jwt}`,
253+
},
244254
});
245255

246256
if (!response.ok) {
@@ -276,6 +286,7 @@ export const useCreateSchemaMutation = () => {
276286
{
277287
method: 'POST',
278288
headers: {
289+
Authorization: `Bearer ${config.jwt}`,
279290
'Content-Type': 'application/json',
280291
},
281292
body: JSON.stringify({
@@ -333,6 +344,7 @@ export const useValidateSchemaMutation = () =>
333344
{
334345
method: 'POST',
335346
headers: {
347+
Authorization: `Bearer ${config.jwt}`,
336348
'Content-Type': 'application/json',
337349
},
338350
body: JSON.stringify({
@@ -368,11 +380,13 @@ export const useSchemaReferencedByQuery = (subjectName: string, version: number,
368380
return useTanstackQuery<{ schemaId: number; error?: string; usages: { subject: string; version: number }[] }[]>({
369381
queryKey: ['schemaRegistry', 'subjects', subjectName, 'versions', version, 'referencedby'],
370382
queryFn: async () => {
371-
const response = await config.fetch(
383+
const response = await fetch(
372384
`${config.restBasePath}/schema-registry/subjects/${encodeURIComponent(subjectName)}/versions/${version}/referencedby`,
373385
{
374386
method: 'GET',
375-
headers: {},
387+
headers: {
388+
Authorization: `Bearer ${config.jwt}`,
389+
},
376390
}
377391
);
378392

@@ -406,6 +420,7 @@ export const useDeleteSchemaVersionMutation = () => {
406420
{
407421
method: 'DELETE',
408422
headers: {
423+
Authorization: `Bearer ${config.jwt}`,
409424
'Content-Type': 'application/json',
410425
},
411426
}
@@ -444,7 +459,9 @@ export const useSchemaUsagesByIdQuery = (schemaId: number | null) => {
444459

445460
const response = await config.fetch(`${config.restBasePath}/schema-registry/schemas/ids/${schemaId}/versions`, {
446461
method: 'GET',
447-
headers: {},
462+
headers: {
463+
Authorization: `Bearer ${config.jwt}`,
464+
},
448465
});
449466

450467
if (!response.ok) {

0 commit comments

Comments
 (0)