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/useAnonRoute.js

16 lines
390 B
JavaScript

import useSWR from "swr";
import { useRouter } from "next/router";
import { StatusCodes } from "http-status-codes";
const fetcher = (url, router) => {
return fetch(url).then((res) => {
if (res.status === StatusCodes.OK) router.push("/");
});
};
export default function useAnonRoute() {
const router = useRouter();
return useSWR("/api/user", (url) => fetcher(url, router));
}