el.xwx.moe/hooks/useInitialData.tsx

26 lines
749 B
TypeScript
Raw Normal View History

2023-03-22 18:11:54 -05:00
import useCollectionStore from "@/store/collections";
2023-02-18 21:32:02 -06:00
import { useEffect } from "react";
import { useSession } from "next-auth/react";
2023-03-22 18:11:54 -05:00
import useTagStore from "@/store/tags";
2023-05-18 13:02:17 -05:00
import useAccountStore from "@/store/account";
2023-02-18 21:32:02 -06:00
export default function useInitialData() {
2023-05-18 13:02:17 -05:00
const { status, data } = useSession();
2023-03-22 18:11:54 -05:00
const { setCollections } = useCollectionStore();
const { setTags } = useTagStore();
// const { setLinks } = useLinkStore();
2023-05-18 13:02:17 -05:00
const { setAccount } = useAccountStore();
2023-02-18 21:32:02 -06:00
useEffect(() => {
2023-08-03 13:03:06 -05:00
if (
status === "authenticated" &&
(!process.env.NEXT_PUBLIC_STRIPE_IS_ACTIVE || data.user.isSubscriber)
) {
2023-02-18 21:32:02 -06:00
setCollections();
setTags();
// setLinks();
setAccount(data.user.id);
2023-02-18 21:32:02 -06:00
}
}, [status]);
}