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.
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();
|
|
|
|
|
2022-03-18 15:45:01 +00:00
|
|
|
return useSWR("/api/user", (url) => fetcher(url, router));
|
2021-11-13 00:13:34 +00:00
|
|
|
}
|