feat(signup): allow to block signup (#3209)
* feat(signup): allow to block signup * feat(signup): update environment variable documentation * test: update auth service tests * feat(signup): prevent user from reaching out the sign up page * Fix lint * Fixes --------- Co-authored-by: Charles Bochet <charles@twenty.com>
This commit is contained in:
committed by
GitHub
parent
66a054ac21
commit
c6ae480856
@ -1,10 +1,12 @@
|
||||
import { useEffect, useState } from 'react';
|
||||
import { matchPath, useLocation, useNavigate } from 'react-router-dom';
|
||||
import { useRecoilValue } from 'recoil';
|
||||
|
||||
import { useOpenCreateActivityDrawer } from '@/activities/hooks/useOpenCreateActivityDrawer';
|
||||
import { useEventTracker } from '@/analytics/hooks/useEventTracker';
|
||||
import { useOnboardingStatus } from '@/auth/hooks/useOnboardingStatus';
|
||||
import { OnboardingStatus } from '@/auth/utils/getOnboardingStatus';
|
||||
import { isSignUpDisabledState } from '@/client-config/states/isSignUpDisabledState';
|
||||
import { useCommandMenu } from '@/command-menu/hooks/useCommandMenu';
|
||||
import { CommandType } from '@/command-menu/types/Command';
|
||||
import { TableHotkeyScope } from '@/object-record/record-table/types/TableHotkeyScope';
|
||||
@ -41,6 +43,8 @@ export const PageChangeEffect = () => {
|
||||
|
||||
const openCreateActivity = useOpenCreateActivityDrawer();
|
||||
|
||||
const isSignUpDisabled = useRecoilValue(isSignUpDisabledState);
|
||||
|
||||
useEffect(() => {
|
||||
if (!previousLocation || previousLocation !== location.pathname) {
|
||||
setPreviousLocation(location.pathname);
|
||||
@ -115,10 +119,13 @@ export const PageChangeEffect = () => {
|
||||
navigateToSignUp();
|
||||
},
|
||||
});
|
||||
} else if (isMatchingLocation(AppPath.SignUp) && isSignUpDisabled) {
|
||||
navigate(AppPath.SignIn);
|
||||
}
|
||||
}, [
|
||||
enqueueSnackBar,
|
||||
isMatchingLocation,
|
||||
isSignUpDisabled,
|
||||
location.pathname,
|
||||
navigate,
|
||||
onboardingStatus,
|
||||
|
||||
@ -72,6 +72,7 @@ export type ClientConfig = {
|
||||
debugMode: Scalars['Boolean'];
|
||||
sentry: Sentry;
|
||||
signInPrefilled: Scalars['Boolean'];
|
||||
signUpDisabled: Scalars['Boolean'];
|
||||
support: Support;
|
||||
telemetry: Telemetry;
|
||||
};
|
||||
@ -746,7 +747,7 @@ export type CheckUserExistsQuery = { __typename?: 'Query', checkUserExists: { __
|
||||
export type GetClientConfigQueryVariables = Exact<{ [key: string]: never; }>;
|
||||
|
||||
|
||||
export type GetClientConfigQuery = { __typename?: 'Query', clientConfig: { __typename?: 'ClientConfig', signInPrefilled: boolean, debugMode: boolean, authProviders: { __typename?: 'AuthProviders', google: boolean, password: boolean }, billing: { __typename?: 'Billing', isBillingEnabled: boolean, billingUrl: string }, telemetry: { __typename?: 'Telemetry', enabled: boolean, anonymizationEnabled: boolean }, support: { __typename?: 'Support', supportDriver: string, supportFrontChatId?: string | null }, sentry: { __typename?: 'Sentry', dsn: string } } };
|
||||
export type GetClientConfigQuery = { __typename?: 'Query', clientConfig: { __typename?: 'ClientConfig', signInPrefilled: boolean, signUpDisabled: boolean, debugMode: boolean, authProviders: { __typename?: 'AuthProviders', google: boolean, password: boolean }, billing: { __typename?: 'Billing', isBillingEnabled: boolean, billingUrl: string }, telemetry: { __typename?: 'Telemetry', enabled: boolean, anonymizationEnabled: boolean }, support: { __typename?: 'Support', supportDriver: string, supportFrontChatId?: string | null }, sentry: { __typename?: 'Sentry', dsn: string } } };
|
||||
|
||||
export type UploadFileMutationVariables = Exact<{
|
||||
file: Scalars['Upload'];
|
||||
@ -1281,6 +1282,7 @@ export const GetClientConfigDocument = gql`
|
||||
billingUrl
|
||||
}
|
||||
signInPrefilled
|
||||
signUpDisabled
|
||||
debugMode
|
||||
telemetry {
|
||||
enabled
|
||||
|
||||
@ -5,6 +5,7 @@ import { authProvidersState } from '@/client-config/states/authProvidersState';
|
||||
import { billingState } from '@/client-config/states/billingState';
|
||||
import { isDebugModeState } from '@/client-config/states/isDebugModeState';
|
||||
import { isSignInPrefilledState } from '@/client-config/states/isSignInPrefilledState';
|
||||
import { isSignUpDisabledState } from '@/client-config/states/isSignUpDisabledState';
|
||||
import { sentryConfigState } from '@/client-config/states/sentryConfigState';
|
||||
import { supportChatState } from '@/client-config/states/supportChatState';
|
||||
import { telemetryState } from '@/client-config/states/telemetryState';
|
||||
@ -17,6 +18,7 @@ export const ClientConfigProvider: React.FC<React.PropsWithChildren> = ({
|
||||
const setIsDebugMode = useSetRecoilState(isDebugModeState);
|
||||
|
||||
const setIsSignInPrefilled = useSetRecoilState(isSignInPrefilledState);
|
||||
const setIsSignUpDisabled = useSetRecoilState(isSignUpDisabledState);
|
||||
|
||||
const setBilling = useSetRecoilState(billingState);
|
||||
const setTelemetry = useSetRecoilState(telemetryState);
|
||||
@ -35,6 +37,7 @@ export const ClientConfigProvider: React.FC<React.PropsWithChildren> = ({
|
||||
});
|
||||
setIsDebugMode(data?.clientConfig.debugMode);
|
||||
setIsSignInPrefilled(data?.clientConfig.signInPrefilled);
|
||||
setIsSignUpDisabled(data?.clientConfig.signUpDisabled);
|
||||
|
||||
setBilling(data?.clientConfig.billing);
|
||||
setTelemetry(data?.clientConfig.telemetry);
|
||||
@ -49,6 +52,7 @@ export const ClientConfigProvider: React.FC<React.PropsWithChildren> = ({
|
||||
setAuthProviders,
|
||||
setIsDebugMode,
|
||||
setIsSignInPrefilled,
|
||||
setIsSignUpDisabled,
|
||||
setTelemetry,
|
||||
setSupportChat,
|
||||
setBilling,
|
||||
|
||||
@ -12,6 +12,7 @@ export const GET_CLIENT_CONFIG = gql`
|
||||
billingUrl
|
||||
}
|
||||
signInPrefilled
|
||||
signUpDisabled
|
||||
debugMode
|
||||
telemetry {
|
||||
enabled
|
||||
|
||||
@ -0,0 +1,6 @@
|
||||
import { atom } from 'recoil';
|
||||
|
||||
export const isSignUpDisabledState = atom<boolean>({
|
||||
key: 'isSignUpDisabledState',
|
||||
default: false,
|
||||
});
|
||||
@ -1,5 +1,6 @@
|
||||
export const mockedClientConfig = {
|
||||
signInPrefilled: true,
|
||||
signUpDisabled: false,
|
||||
dataModelSettingsEnabled: true,
|
||||
developersSettingsEnabled: true,
|
||||
debugMode: false,
|
||||
|
||||
Reference in New Issue
Block a user