Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deploy passwordless auth feature for WooCommerce.com #90359

Merged
merged 2 commits into from
May 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions client/blocks/authentication/social/social-tos.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { localizeUrl } from '@automattic/i18n-utils';
import { localize } from 'i18n-calypso';
import { connect } from 'react-redux';
import { getCurrentOAuth2Client } from 'calypso/state/oauth2-clients/ui/selectors';
import getWooPasswordless from 'calypso/state/selectors/get-woo-passwordless';
import getIsWooPasswordless from 'calypso/state/selectors/get-is-woo-passwordless';

const toSLinks = {
components: {
Expand Down Expand Up @@ -47,5 +47,5 @@ function SocialAuthToS( props ) {

export default connect( ( state ) => ( {
oauth2Client: getCurrentOAuth2Client( state ),
isWooPasswordless: !! getWooPasswordless( state ),
isWooPasswordless: getIsWooPasswordless( state ),
} ) )( localize( SocialAuthToS ) );
4 changes: 2 additions & 2 deletions client/blocks/login/continue-as-user.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import Gravatar from 'calypso/components/gravatar';
import wpcom from 'calypso/lib/wp';
import { getCurrentUser } from 'calypso/state/current-user/selectors';
import { getCurrentQueryArguments } from 'calypso/state/selectors/get-current-query-arguments';
import getWooPasswordless from 'calypso/state/selectors/get-woo-passwordless';
import getIsWooPasswordless from 'calypso/state/selectors/get-is-woo-passwordless';

import './continue-as-user.scss';

Expand Down Expand Up @@ -180,5 +180,5 @@ function ContinueAsUser( {
export default connect( ( state ) => ( {
currentUser: getCurrentUser( state ),
redirectUrlFromQuery: get( getCurrentQueryArguments( state ), 'redirect_to', null ),
isWooPasswordless: !! getWooPasswordless( state ),
isWooPasswordless: getIsWooPasswordless( state ),
} ) )( ContinueAsUser );
4 changes: 2 additions & 2 deletions client/blocks/login/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,9 @@ import { getCurrentOAuth2Client } from 'calypso/state/oauth2-clients/ui/selector
import getCurrentQueryArguments from 'calypso/state/selectors/get-current-query-arguments';
import getCurrentRoute from 'calypso/state/selectors/get-current-route';
import getInitialQueryArguments from 'calypso/state/selectors/get-initial-query-arguments';
import getIsWooPasswordless from 'calypso/state/selectors/get-is-woo-passwordless';
import getPartnerSlugFromQuery from 'calypso/state/selectors/get-partner-slug-from-query';
import getWccomFrom from 'calypso/state/selectors/get-wccom-from';
import getWooPasswordless from 'calypso/state/selectors/get-woo-passwordless';
import isFetchingMagicLoginEmail from 'calypso/state/selectors/is-fetching-magic-login-email';
import isMagicLoginEmailRequested from 'calypso/state/selectors/is-magic-login-email-requested';
import isWooCommerceCoreProfilerFlow from 'calypso/state/selectors/is-woocommerce-core-profiler-flow';
Expand Down Expand Up @@ -991,7 +991,7 @@ export default connect(
'woocommerce-onboarding' === get( getCurrentQueryArguments( state ), 'from' ),
isWooCoreProfilerFlow: isWooCommerceCoreProfilerFlow( state ),
wccomFrom: getWccomFrom( state ),
isWooPasswordless: !! getWooPasswordless( state ),
isWooPasswordless: getIsWooPasswordless( state ),
isAnchorFmSignup: getIsAnchorFmSignup(
get( getCurrentQueryArguments( state ), 'redirect_to' )
),
Expand Down
4 changes: 2 additions & 2 deletions client/blocks/login/login-form.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ import { getCurrentOAuth2Client } from 'calypso/state/oauth2-clients/ui/selector
import getCurrentQueryArguments from 'calypso/state/selectors/get-current-query-arguments';
import getCurrentRoute from 'calypso/state/selectors/get-current-route';
import getInitialQueryArguments from 'calypso/state/selectors/get-initial-query-arguments';
import getIsWooPasswordless from 'calypso/state/selectors/get-is-woo-passwordless';
import getWccomFrom from 'calypso/state/selectors/get-wccom-from';
import getWooPasswordless from 'calypso/state/selectors/get-woo-passwordless';
import isWooCommerceCoreProfilerFlow from 'calypso/state/selectors/is-woocommerce-core-profiler-flow';
import ErrorNotice from './error-notice';
import SocialLoginForm from './social';
Expand Down Expand Up @@ -1068,7 +1068,7 @@ export default connect(
getCurrentQueryArguments( state )?.email_address,
wccomFrom: getWccomFrom( state ),
currentQuery: getCurrentQueryArguments( state ),
isWooPasswordless: !! getWooPasswordless( state ),
isWooPasswordless: getIsWooPasswordless( state ),
};
},
{
Expand Down
4 changes: 2 additions & 2 deletions client/blocks/signup-form/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ import { getCurrentUser } from 'calypso/state/current-user/selectors';
import { createSocialUserFailed } from 'calypso/state/login/actions';
import { getCurrentOAuth2Client } from 'calypso/state/oauth2-clients/ui/selectors';
import getCurrentQueryArguments from 'calypso/state/selectors/get-current-query-arguments';
import getIsWooPasswordless from 'calypso/state/selectors/get-is-woo-passwordless';
import getWccomFrom from 'calypso/state/selectors/get-wccom-from';
import getWooPasswordless from 'calypso/state/selectors/get-woo-passwordless';
import isWooCommerceCoreProfilerFlow from 'calypso/state/selectors/is-woocommerce-core-profiler-flow';
import { resetSignup } from 'calypso/state/signup/actions';
import { getSectionName } from 'calypso/state/ui/selectors';
Expand Down Expand Up @@ -1374,7 +1374,7 @@ export default connect(
isJetpackWooDnaFlow: wooDnaConfig( getCurrentQueryArguments( state ) ).isWooDnaFlow(),
from: get( getCurrentQueryArguments( state ), 'from' ),
wccomFrom: getWccomFrom( state ),
isWooPasswordless: !! getWooPasswordless( state ),
isWooPasswordless: getIsWooPasswordless( state ),
isWoo: isWooOAuth2Client( oauth2Client ) || isWooCoreProfilerFlow,
isWooCoreProfilerFlow,
isP2Flow:
Expand Down
11 changes: 2 additions & 9 deletions client/layout/logged-out.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ import { clearLastActionRequiresLogin } from 'calypso/state/reader-ui/actions';
import { getLastActionRequiresLogin } from 'calypso/state/reader-ui/selectors';
import getCurrentRoute from 'calypso/state/selectors/get-current-route';
import getInitialQueryArguments from 'calypso/state/selectors/get-initial-query-arguments';
import getIsWooPasswordless from 'calypso/state/selectors/get-is-woo-passwordless';
import getWccomFrom from 'calypso/state/selectors/get-wccom-from';
import getWooPasswordless from 'calypso/state/selectors/get-woo-passwordless';
import isWooCommerceCoreProfilerFlow from 'calypso/state/selectors/is-woocommerce-core-profiler-flow';
import { masterbarIsVisible } from 'calypso/state/ui/selectors';
import BodySectionCssClass from './body-section-css-class';
Expand Down Expand Up @@ -350,13 +350,6 @@ export default withCurrentRoute(
noMasterbarForSection ||
noMasterbarForRoute;

const isWCCOM = isWooOAuth2Client( oauth2Client ) && wccomFrom !== null;
const wooPasswordless = getWooPasswordless( state );
const isWooPasswordless =
!! wooPasswordless &&
// Enable woo-passwordless feature for WCCOM only.
isWCCOM;

return {
isJetpackLogin,
isWhiteLogin,
Expand All @@ -377,7 +370,7 @@ export default withCurrentRoute(
isPartnerSignup,
isPartnerSignupStart,
isWooCoreProfilerFlow,
isWooPasswordless,
isWooPasswordless: getIsWooPasswordless( state ),
};
},
{ clearLastActionRequiresLogin }
Expand Down
5 changes: 0 additions & 5 deletions client/login/index.web.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import {
makeLayoutMiddleware,
} from 'calypso/controller/shared';
import LayoutLoggedOut from 'calypso/layout/logged-out';
import signupController from 'calypso/signup/controller';
import {
login,
magicLogin,
Expand Down Expand Up @@ -68,7 +67,6 @@ export default ( router ) => {
redirectLoggedIn,
setLocaleMiddleware(),
setSectionMiddleware( LOGIN_SECTION_DEFINITION ),
signupController.redirectWooPasswordless,
magicLoginUse,
makeLoggedOutLayout
);
Expand All @@ -77,7 +75,6 @@ export default ( router ) => {
[ `/log-in/link/${ lang }`, `/log-in/jetpack/link/${ lang }`, `/log-in/new/link/${ lang }` ],
setLocaleMiddleware(),
setSectionMiddleware( LOGIN_SECTION_DEFINITION ),
signupController.redirectWooPasswordless,
magicLogin,
makeLoggedOutLayout
);
Expand All @@ -88,7 +85,6 @@ export default ( router ) => {
redirectLoggedIn,
setLocaleMiddleware(),
setSectionMiddleware( LOGIN_SECTION_DEFINITION ),
signupController.redirectWooPasswordless,
qrCodeLogin,
makeLoggedOutLayout
);
Expand All @@ -111,7 +107,6 @@ export default ( router ) => {
setLocaleMiddleware(),
setHrefLangLinks,
setSectionMiddleware( LOGIN_SECTION_DEFINITION ),
signupController.redirectWooPasswordless,
login,
setShouldServerSideRenderLogin,
makeLoggedOutLayout
Expand Down
4 changes: 2 additions & 2 deletions client/login/wp-login/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ import getCurrentLocaleSlug from 'calypso/state/selectors/get-current-locale-slu
import getCurrentQueryArguments from 'calypso/state/selectors/get-current-query-arguments';
import getCurrentRoute from 'calypso/state/selectors/get-current-route';
import getInitialQueryArguments from 'calypso/state/selectors/get-initial-query-arguments';
import getWooPasswordless from 'calypso/state/selectors/get-woo-passwordless';
import getIsWooPasswordless from 'calypso/state/selectors/get-is-woo-passwordless';
import isWooCommerceCoreProfilerFlow from 'calypso/state/selectors/is-woocommerce-core-profiler-flow';
import { withEnhancers } from 'calypso/state/utils';
import LoginButtons from './login-buttons';
Expand Down Expand Up @@ -636,7 +636,7 @@ export default connect(
isFromMigrationPlugin: startsWith( get( currentQuery, 'from' ), 'wpcom-migration' ),
isWooCoreProfilerFlow: isWooCommerceCoreProfilerFlow( state ),
isWoo: isWooOAuth2Client( oauth2Client ),
isWooPasswordless: getWooPasswordless( state ),
isWooPasswordless: getIsWooPasswordless( state ),
currentRoute,
currentQuery,
redirectTo: getRedirectToOriginal( state ),
Expand Down
54 changes: 1 addition & 53 deletions client/signup/controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,10 @@ import store from 'store';
import { notFound } from 'calypso/controller';
import { recordPageView } from 'calypso/lib/analytics/page-view';
import { loadExperimentAssignment } from 'calypso/lib/explat';
import { isWooOAuth2Client } from 'calypso/lib/oauth2-clients.js';
import { login } from 'calypso/lib/paths';
import { sectionify, addQueryArgs } from 'calypso/lib/route';
import { sectionify } from 'calypso/lib/route';
import flows from 'calypso/signup/config/flows';
import { getCurrentUserSiteCount, isUserLoggedIn } from 'calypso/state/current-user/selectors';
import { getCurrentOAuth2Client } from 'calypso/state/oauth2-clients/ui/selectors.js';
import getCurrentQueryArguments from 'calypso/state/selectors/get-current-query-arguments';
import getCurrentRoute from 'calypso/state/selectors/get-current-route.js';
import getPreviousQuery from 'calypso/state/selectors/get-previous-query';
import getWccomFrom from 'calypso/state/selectors/get-wccom-from';
import getWooPasswordless from 'calypso/state/selectors/get-woo-passwordless';
import { updateDependencies } from 'calypso/state/signup/actions';
import { getSignupDependencyStore } from 'calypso/state/signup/dependency-store/selectors';
import { setCurrentFlowName, setPreviousFlowName } from 'calypso/state/signup/flow/actions';
Expand Down Expand Up @@ -430,49 +423,4 @@ export default {
} );
}
},

async redirectWooPasswordless( context, next ) {
if ( ! config.isEnabled( 'woo/passwordless' ) ) {
next();
return;
}

const state = context.store.getState();
const oauth2Client = getCurrentOAuth2Client( state );
const wccomFrom = getWccomFrom( state );
const isWCCOM = isWooOAuth2Client( oauth2Client ) && wccomFrom !== null;
const wooPasswordless = getWooPasswordless( state );

if ( ! isWCCOM ) {
// Only enable Woo passwordless for WooCommerce.com users
next();
return;
}

if ( wooPasswordless ) {
// Woo passwordless is already enabled via query parameter
next();
return;
}

const previousQuery = getPreviousQuery( state );

if ( ! previousQuery || ! previousQuery[ 'woo-passwordless' ] ) {
// If the previous page did not have the woo-passwordless query parameter, fetch the experiment assignment. Otherwise, skip the experiment assignment.

const experimentAssignment = await loadExperimentAssignment(
'calypso_wooexpress_signup_passwordless_registration_202404_v1'
);
if ( experimentAssignment.variationName !== 'treatment' ) {
next();
return;
}
}

// Add the woo-passwordless query parameter to the URL.
const currentRoute = getCurrentRoute( state );
const currentQuery = getCurrentQueryArguments( state );
const queryParams = { ...currentQuery, 'woo-passwordless': 'yes' };
return page.replace( addQueryArgs( queryParams, currentRoute ) );
},
};
1 change: 0 additions & 1 deletion client/signup/index.web.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ export default function () {
controller.saveInitialContext,
controller.redirectWithoutLocaleIfLoggedIn,
controller.redirectToFlow,
controller.redirectWooPasswordless,
controller.setSelectedSiteForSignup,
controller.start,
makeLayout,
Expand Down
4 changes: 2 additions & 2 deletions client/signup/steps/user/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ import { errorNotice } from 'calypso/state/notices/actions';
import { fetchOAuth2ClientData } from 'calypso/state/oauth2-clients/actions';
import { getCurrentOAuth2Client } from 'calypso/state/oauth2-clients/ui/selectors';
import getCurrentQueryArguments from 'calypso/state/selectors/get-current-query-arguments';
import getIsWooPasswordless from 'calypso/state/selectors/get-is-woo-passwordless';
import getWccomFrom from 'calypso/state/selectors/get-wccom-from';
import getWooPasswordless from 'calypso/state/selectors/get-woo-passwordless';
import { getSuggestedUsername } from 'calypso/state/signup/optional-dependencies/selectors';
import { saveSignupStep, submitSignupStep } from 'calypso/state/signup/progress/actions';

Expand Down Expand Up @@ -748,7 +748,7 @@ const ConnectedUser = connect(
oauth2Client: getCurrentOAuth2Client( state ),
suggestedUsername: getSuggestedUsername( state ),
wccomFrom: getWccomFrom( state ),
isWooPasswordless: !! getWooPasswordless( state ),
isWooPasswordless: getIsWooPasswordless( state ),
from: get( getCurrentQueryArguments( state ), 'from' ),
userLoggedIn: isUserLoggedIn( state ),
};
Expand Down
19 changes: 19 additions & 0 deletions client/state/selectors/get-is-woo-passwordless.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import 'calypso/state/route/init';
import config from '@automattic/calypso-config';
import { isWooOAuth2Client } from 'calypso/lib/oauth2-clients';
import { getCurrentOAuth2Client } from '../oauth2-clients/ui/selectors';
import getWccomFrom from './get-wccom-from';
import type { AppState } from 'calypso/types';

/**
* Return if should enable Woo Passwordless authentication.
*
*/
export default function getIsWooPasswordless( state: AppState ): boolean {
if ( ! config.isEnabled( 'woo/passwordless' ) ) {
return false;
}

// Enable Woo Passwordless only if user is from WooCommerce.com. Not enable for other flows such as "Core Profiler" for now.
return isWooOAuth2Client( getCurrentOAuth2Client( state ) ) && getWccomFrom( state ) !== null;
}
11 changes: 0 additions & 11 deletions client/state/selectors/get-woo-passwordless.ts

This file was deleted.

Loading