ha-frontend-cdce8p/src/util/fetch-with-auth.js
Paulus Schoutsen 34bfc12647
Prettier 💎 (#1737)
* Add prettier

* Apply Prettier
2018-10-11 12:22:11 +02:00

10 lines
303 B
JavaScript

export const fetchWithAuth = async (auth, input, init = {}) => {
if (auth.expired) await auth.refreshAccessToken();
init.credentials = "same-origin";
if (!init.headers) {
init.headers = {};
}
init.headers.authorization = `Bearer ${auth.accessToken}`;
return await fetch(input, init);
};