Newer
Older
taehui / taehui-fe / src / taehui / useSession.ts
@Taehui Taehui on 13 Mar 640 bytes v1.0.0
import { useEffect, useState } from "react";

import { useAvatarStore } from "src/Stores";
import useAutoSignIn from "src/avatar/useAutoSignIn";

const useSession = () => {
  const { loadTotem, totem } = useAvatarStore();
  const [isLoading, setLoading] = useState(true);

  const autoSignIn = useAutoSignIn();

  useEffect(() => {
    (async () => {
      await loadTotem();
      setLoading(false);
    })();
  }, [loadTotem]);

  useEffect(() => {
    (async () => {
      if (!isLoading && !totem) {
        await autoSignIn();
      }
    })();
  }, [autoSignIn, isLoading, totem]);

  return isLoading;
};

export default useSession;