Allow configuring authProvider in place of registrations

This commit is contained in:
Alex Gleason 2022-08-11 22:06:38 -05:00
parent d6e809083b
commit f2fc369877
No known key found for this signature in database
GPG key ID: 7211D1F99744FBB7
4 changed files with 42 additions and 9 deletions

View file

@ -4,6 +4,7 @@ import { useIntl, defineMessages } from 'react-intl';
import { prepareRequest } from 'soapbox/actions/consumer-auth'; import { prepareRequest } from 'soapbox/actions/consumer-auth';
import { IconButton, Tooltip } from 'soapbox/components/ui'; import { IconButton, Tooltip } from 'soapbox/components/ui';
import { useAppDispatch } from 'soapbox/hooks'; import { useAppDispatch } from 'soapbox/hooks';
import { capitalize } from 'soapbox/utils/strings';
const messages = defineMessages({ const messages = defineMessages({
tooltip: { id: 'oauth_consumer.tooltip', defaultMessage: 'Sign in with {provider}' }, tooltip: { id: 'oauth_consumer.tooltip', defaultMessage: 'Sign in with {provider}' },
@ -19,12 +20,6 @@ const BRAND_ICONS: Record<string, string> = {
github: require('@tabler/icons/brand-github.svg'), github: require('@tabler/icons/brand-github.svg'),
}; };
/** Capitalize the first letter of a string. */
// https://stackoverflow.com/a/1026087
function capitalize(str: string) {
return str.charAt(0).toUpperCase() + str.slice(1);
}
interface IConsumerButton { interface IConsumerButton {
provider: string, provider: string,
} }

View file

@ -1,12 +1,15 @@
import * as React from 'react'; import * as React from 'react';
import { FormattedMessage } from 'react-intl'; import { FormattedMessage } from 'react-intl';
import { prepareRequest } from 'soapbox/actions/consumer-auth';
import { Button, Card, CardBody, Stack, Text } from 'soapbox/components/ui'; import { Button, Card, CardBody, Stack, Text } from 'soapbox/components/ui';
import VerificationBadge from 'soapbox/components/verification_badge'; import VerificationBadge from 'soapbox/components/verification_badge';
import RegistrationForm from 'soapbox/features/auth_login/components/registration_form'; import RegistrationForm from 'soapbox/features/auth_login/components/registration_form';
import { useAppSelector, useFeatures, useSoapboxConfig } from 'soapbox/hooks'; import { useAppDispatch, useAppSelector, useFeatures, useSoapboxConfig } from 'soapbox/hooks';
import { capitalize } from 'soapbox/utils/strings';
const LandingPage = () => { const LandingPage = () => {
const dispatch = useAppDispatch();
const features = useFeatures(); const features = useFeatures();
const soapboxConfig = useSoapboxConfig(); const soapboxConfig = useSoapboxConfig();
const pepeEnabled = soapboxConfig.getIn(['extensions', 'pepe', 'enabled']) === true; const pepeEnabled = soapboxConfig.getIn(['extensions', 'pepe', 'enabled']) === true;
@ -40,6 +43,29 @@ const LandingPage = () => {
return <RegistrationForm />; return <RegistrationForm />;
}; };
/** Display login button for external provider. */
const renderProvider = () => {
const { authProvider } = soapboxConfig;
return (
<Stack space={3}>
<Stack>
<Text size='2xl' weight='bold' align='center'>
<FormattedMessage id='registrations.get_started' defaultMessage="Let's get started!" />
</Text>
</Stack>
<Button onClick={() => dispatch(prepareRequest(authProvider))} theme='primary' block>
<FormattedMessage
id='oauth_consumer.tooltip'
defaultMessage='Sign in with {provider}'
values={{ provider: capitalize(authProvider) }}
/>
</Button>
</Stack>
);
};
/** Pepe API registrations are open */ /** Pepe API registrations are open */
const renderPepe = () => { const renderPepe = () => {
return ( return (
@ -47,7 +73,9 @@ const LandingPage = () => {
<VerificationBadge className='h-16 w-16 mx-auto' /> <VerificationBadge className='h-16 w-16 mx-auto' />
<Stack> <Stack>
<Text size='2xl' weight='bold' align='center'>Let&apos;s get started!</Text> <Text size='2xl' weight='bold' align='center'>
<FormattedMessage id='registrations.get_started' defaultMessage="Let's get started!" />
</Text>
<Text theme='muted' align='center'>Social Media Without Discrimination</Text> <Text theme='muted' align='center'>Social Media Without Discrimination</Text>
</Stack> </Stack>
@ -58,7 +86,9 @@ const LandingPage = () => {
// Render registration flow depending on features // Render registration flow depending on features
const renderBody = () => { const renderBody = () => {
if (pepeEnabled && pepeOpen) { if (soapboxConfig.authProvider) {
return renderProvider();
} else if (pepeEnabled && pepeOpen) {
return renderPepe(); return renderPepe();
} else if (features.accountCreation && instance.registrations) { } else if (features.accountCreation && instance.registrations) {
return renderOpen(); return renderOpen();

View file

@ -71,6 +71,7 @@ export const CryptoAddressRecord = ImmutableRecord({
export const SoapboxConfigRecord = ImmutableRecord({ export const SoapboxConfigRecord = ImmutableRecord({
ads: ImmutableList<Ad>(), ads: ImmutableList<Ad>(),
appleAppId: null, appleAppId: null,
authProvider: '',
logo: '', logo: '',
logoDarkMode: null, logoDarkMode: null,
banner: '', banner: '',

View file

@ -0,0 +1,7 @@
/** Capitalize the first letter of a string. */
// https://stackoverflow.com/a/1026087
function capitalize(str: string) {
return str.charAt(0).toUpperCase() + str.slice(1);
}
export { capitalize };