fix: authorization
This commit is contained in:
1 parent
a3fb95eca1
commit
fbbd7b52e3
7 files changed
+54
-36
No files matched your search
@@ -25,17 +25,23 @@ class Http {
|
||||
body?: B;
|
||||
preventCache?: boolean;
|
||||
}): Promise<T> {
|
||||
const serializedParams = new URLSearchParams(
|
||||
const searchParams = new URLSearchParams(
|
||||
Object.entries(search ?? {}).reduce((params, [key, value]) => {
|
||||
if (value != null && value !== '') {
|
||||
params.set(key, String(value));
|
||||
}
|
||||
return params;
|
||||
}, new URLSearchParams())
|
||||
).toString();
|
||||
);
|
||||
|
||||
if (preventCache) {
|
||||
searchParams.append('preventCache', '1');
|
||||
}
|
||||
|
||||
const searchParamsString = searchParams.toString();
|
||||
|
||||
try {
|
||||
const response = await fetch(`${base}${url}${serializedParams ? `?${serializedParams}` : ''}`, {
|
||||
const response = await fetch(`${base}${url}${searchParamsString ? `?${searchParamsString}` : ''}`, {
|
||||
method,
|
||||
headers: {
|
||||
Authorization: this.authorization || '',
|
||||
|
||||
@@ -1,7 +0,0 @@
|
||||
import { MOVIE_DB_API_URL, MOVIE_DB_TOKEN } from '@/env';
|
||||
|
||||
import Http from './Http';
|
||||
|
||||
const movieDB = new Http(MOVIE_DB_API_URL, `Bearer ${MOVIE_DB_TOKEN}`);
|
||||
|
||||
export default movieDB;
|
||||
Reference in new issue
Block a user