refactor: set api authorization headers

This commit is contained in:
kunish 2023-09-13 15:26:40 +08:00
parent fd1153709e
commit 8483d313c5
No known key found for this signature in database
GPG Key ID: 647A12B4F782C430

View File

@ -26,9 +26,19 @@ export const [endpointList, setEndpointList] = makePersisted(
export const useRequest = () => {
const e = endpoint()
if (!e) {
return ky.create({})
}
const headers = new Headers()
if (e.secret) {
headers.set('Authorization', `Bearer ${e.secret}`)
}
return ky.create({
prefixUrl: e?.url,
headers: { Authorization: e?.secret ? `Bearer ${e.secret}` : '' },
prefixUrl: e.url,
headers,
})
}