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

18 lines
520 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";
2022-02-09 13:13:53 +00:00
const prefix = process.env.NEXT_PUBLIC_PORTAL_DOMAIN ? `https://account.${process.env.NEXT_PUBLIC_PORTAL_DOMAIN}` : "";
2021-11-13 00:13:34 +00:00
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(`${prefix}/api/user`, (url) => fetcher(url, router));
}