Skip to content

Commit 57a0ad3

Browse files
committed
added user Token conditionally in headers
1 parent fe803eb commit 57a0ad3

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

src/api/api.js

+8-4
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,18 @@ const commonAPICall = async (
2222
'Content-Type': 'application/json',
2323
},
2424
) => {
25+
const token = tokenLocalStorage();
2526
const FULLPATH = BASE_URL + PATH;
27+
if (token) {
28+
headers = {
29+
...headers,
30+
Authorization: `Bearer ${token}`,
31+
};
32+
}
2633
const response = await fetch(FULLPATH, {
2734
method: METHOD,
2835
body: BODY,
29-
headers: {
30-
...headers,
31-
Authorization: `Bearer ${tokenLocalStorage()}`,
32-
},
36+
headers: headers,
3337
});
3438

3539
return response;

0 commit comments

Comments
 (0)