ExternalAuthButton.tsx 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. import { useCallback } from 'react';
  2. import { useTranslation } from 'next-i18next';
  3. import { IExternalAuthProviderType } from '~/interfaces/external-auth-provider';
  4. const authIcon = {
  5. [IExternalAuthProviderType.google]: <span className="growi-custom-icons align-bottom">google</span>,
  6. [IExternalAuthProviderType.github]: <span className="growi-custom-icons align-bottom">github</span>,
  7. [IExternalAuthProviderType.oidc]: <span className="growi-custom-icons align-bottom">openid</span>,
  8. [IExternalAuthProviderType.saml]: <span className="material-symbols-outlined align-bottom">key</span>,
  9. };
  10. const authLabel = {
  11. [IExternalAuthProviderType.google]: 'Google',
  12. [IExternalAuthProviderType.github]: 'GitHub',
  13. [IExternalAuthProviderType.oidc]: 'OIDC',
  14. [IExternalAuthProviderType.saml]: 'SAML',
  15. };
  16. export const ExternalAuthButton = ({ authType }: {authType: IExternalAuthProviderType}): JSX.Element => {
  17. const { t } = useTranslation();
  18. const key = `btn-auth-${authType.toString()}`;
  19. const btnClass = `btn-auth-${authType.toString()}`;
  20. const handleLoginWithExternalAuth = useCallback(() => {
  21. window.location.href = `/passport/${authType.toString()}`;
  22. }, [authType]);
  23. return (
  24. <button
  25. key={key}
  26. type="button"
  27. className={`btn btn-secondary ${btnClass} my-2 col-10 col-sm-7 mx-auto d-flex`}
  28. onClick={handleLoginWithExternalAuth}
  29. >
  30. <span>{authIcon[authType]}</span>
  31. <span className="flex-grow-1">{t('Sign in with External auth', { signin: authLabel[authType] })}</span>
  32. </button>
  33. );
  34. };