fix: skip auth header on unprotected health status endpoint
This commit is contained in:
parent
9ba47e0ae5
commit
02b8556b02
2 changed files with 9 additions and 5 deletions
|
|
@ -6,17 +6,20 @@ function buildUrl(path: string) {
|
||||||
|
|
||||||
type RequestOptions = Omit<RequestInit, 'body'> & {
|
type RequestOptions = Omit<RequestInit, 'body'> & {
|
||||||
body?: any
|
body?: any
|
||||||
|
skipAuth?: boolean
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function apiFetch<T>(path: string, options: RequestOptions = {}) {
|
export async function apiFetch<T>(path: string, options: RequestOptions = {}) {
|
||||||
const { body, headers, ...rest } = options
|
const { body, headers, skipAuth, ...rest } = options
|
||||||
|
|
||||||
const storedUser = localStorage.getItem('user')
|
|
||||||
let authHeader = {}
|
let authHeader = {}
|
||||||
|
if (!skipAuth) {
|
||||||
|
const storedUser = localStorage.getItem('user')
|
||||||
if (storedUser) {
|
if (storedUser) {
|
||||||
const userData = JSON.parse(storedUser)
|
const userData = JSON.parse(storedUser)
|
||||||
authHeader = { 'Authorization': `Bearer ${userData.jwt}` }
|
authHeader = { 'Authorization': `Bearer ${userData.jwt}` }
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const response = await fetch(buildUrl(path), {
|
const response = await fetch(buildUrl(path), {
|
||||||
...rest,
|
...rest,
|
||||||
|
|
|
||||||
|
|
@ -16,5 +16,6 @@ export type BackendHealthResponse = {
|
||||||
export async function getBackendStatus() {
|
export async function getBackendStatus() {
|
||||||
return apiFetch<BackendHealthResponse>("/q/status", {
|
return apiFetch<BackendHealthResponse>("/q/status", {
|
||||||
method: "GET",
|
method: "GET",
|
||||||
|
skipAuth: true,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue