dashpresshq/dashpress

View on GitHub
src/frontend/hooks/auth/useGuestCheck.ts

Summary

Maintainability
A
0 mins
Test Coverage
A
100%
import { useEffect } from "react";

import { useToggle } from "../state/useToggleState";
import { AuthActions } from "./auth.actions";

export const useGuestCheck = () => {
  const renderMode = useToggle();

  const isClient = typeof window !== "undefined";

  useEffect(() => {
    if (isClient) {
      if (AuthActions.isAuthenticated()) {
        AuthActions.signIn();
      } else {
        renderMode.on();
      }
    }
  }, [isClient]);
  return renderMode.isOn;
};