import { useLogto } from '@logto/react';
import { useCallback } from 'react';
import { useOrgStore } from './useOrganization';

export function useAuth() {
  const { isAuthenticated, isLoading, signOut, signIn } = useLogto();
  const { currentTenantId } = useOrgStore();

  const logout = useCallback(() => {
    sessionStorage.setItem('cameleer:signed_out', '1');
    signOut(window.location.origin + '/platform/login');
  }, [signOut]);

  return {
    isAuthenticated,
    isLoading,
    tenantId: currentTenantId,
    logout,
    signIn,
  };
}
