/* * SPDX-FileCopyrightText: 2022 The HedgeDoc developers (see AUTHORS file) * * SPDX-License-Identifier: AGPL-3.0-only */ import React, { useMemo } from 'react' import { Button } from 'react-bootstrap' import type { ButtonProps } from 'react-bootstrap/Button' import { Trans, useTranslation } from 'react-i18next' import { ShowIf } from '../../common/show-if/show-if' import { useApplicationState } from '../../../hooks/common/use-application-state' import { cypressId } from '../../../utils/cypress-attribute' import Link from 'next/link' import { filterOneClickProviders } from '../../login-page/auth/utils' import { getOneClickProviderMetadata } from '../../login-page/auth/utils/get-one-click-provider-metadata' export type SignInButtonProps = Omit /** * Renders a sign-in button if auth providers are defined. * It links to either the login page or if only a single one-click provider is configured, to that one. * * @param variant The style variant as inferred from the common button component. * @param props Further props inferred from the common button component. */ export const SignInButton: React.FC = ({ variant, ...props }) => { const { t } = useTranslation() const authProviders = useApplicationState((state) => state.config.authProviders) const loginLink = useMemo(() => { const oneClickProviders = authProviders.filter(filterOneClickProviders) if (authProviders.length === 1 && oneClickProviders.length === 1) { const metadata = getOneClickProviderMetadata(oneClickProviders[0]) return metadata.url } return '/login' }, [authProviders]) return ( 0}> ) }