Skip to content

The easy-to-use open source Business Intelligence and Embedded Analytics tool that lets everyone work with data :bar_chart:

907 B
Raw Blame
import { type JSX, useCallback, useEffect } from "react";
import { t } from "ttag";

import {
  AuthCardButton,
  AuthTextButton,
} from "metabase/auth/components/AuthButton";
import { useDispatch } from "metabase/redux";
import { isWithinIframe } from "metabase/utils/iframe";

import { loginSSO } from "../../actions";

interface SsoButtonProps {
  isCard?: boolean;
  redirectUrl?: string;
}

export const SsoButton = ({
  isCard,
  redirectUrl,
}: SsoButtonProps): JSX.Element => {
  const isEmbedded = isWithinIframe();
  const dispatch = useDispatch();

  const handleLogin = useCallback(() => {
    dispatch(loginSSO(redirectUrl));
  }, [dispatch, redirectUrl]);

  useEffect(() => {
    if (isEmbedded) {
      handleLogin();
    }
  }, [isEmbedded, handleLogin]);

  const Button = isCard ? AuthCardButton : AuthTextButton;
  return <Button onClick={handleLogin}>{t`Sign in with SSO`}</Button>;
};