el.xwx.moe/lib/client/getInitialData.ts

29 lines
1.3 KiB
TypeScript
Raw Normal View History

2023-04-23 08:26:39 -05:00
// Copyright (C) 2022-present Daniel31x13 <daniel31x13@gmail.com>
// This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 3.
// This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
// You should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.
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";
import useLinkStore from "@/store/links";
2023-05-18 13:02:17 -05:00
import useAccountStore from "@/store/account";
2023-02-18 21:32:02 -06:00
export default function () {
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(() => {
if (status === "authenticated") {
setCollections();
setTags();
2023-03-05 15:03:20 -06:00
setLinks();
2023-05-22 07:20:48 -05:00
setAccount(data.user.email as string, data.user.id);
2023-02-18 21:32:02 -06:00
}
}, [status]);
}