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
Raw Normal View History

2021-11-13 00:13:34 +00:00
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));
2021-11-13 00:13:34 +00:00
}