This repository has been archived on 2022-10-07. You can view files and clone it, but cannot push or open issues or pull requests.
skynet-webportal/packages/dashboard/src/services/useAccountsApi.js

16 lines
411 B
JavaScript

import useSWR from "swr";
import { StatusCodes } from "http-status-codes";
const fetcher = (url) =>
fetch(url).then((res) => {
if (res.status === StatusCodes.UNAUTHORIZED) {
window.location.href = `/auth/login?return_to=${encodeURIComponent(window.location.href)}`;
}
return res.json();
});
export default function useAccountsApi(key, config) {
return useSWR(key, fetcher, config);
}