Skip to content

Commit

Permalink
Signup: handle passswordless existing accounts (#83767)
Browse files Browse the repository at this point in the history
  • Loading branch information
escapemanuele authored and pull[bot] committed Nov 8, 2023
1 parent d37476d commit 7606242
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 45 deletions.
16 changes: 13 additions & 3 deletions client/blocks/login/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -133,12 +133,20 @@ class Login extends Component {
window.scrollTo( 0, 0 );
}

if ( ! prevProps.accountType && isPasswordlessAccount( this.props.accountType ) ) {
this.props.sendEmailLogin();
this.handleTwoFactorRequested( 'link' );
if (
! prevProps.accountType &&
isPasswordlessAccount( this.props.accountType ) &&
! this.props.isSignupExistingAccount
) {
this.sendMagicLoginLink();
}
}

sendMagicLoginLink = () => {
this.props.sendEmailLogin();
this.handleTwoFactorRequested( 'link' );
};

showContinueAsUser = () => {
const {
isJetpack,
Expand Down Expand Up @@ -724,6 +732,7 @@ class Login extends Component {
handleUsernameChange={ handleUsernameChange }
signupUrl={ signupUrl }
showSocialLoginFormOnly={ true }
sendMagicLoginLink={ this.sendMagicLoginLink }
/>
</Fragment>
);
Expand All @@ -748,6 +757,7 @@ class Login extends Component {
signupUrl={ signupUrl }
hideSignupLink={ isGravPoweredLoginPage }
isSignupExistingAccount={ isSignupExistingAccount }
sendMagicLoginLink={ this.sendMagicLoginLink }
/>
);
}
Expand Down
18 changes: 16 additions & 2 deletions client/blocks/login/login-form.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,11 @@ import {
getSocialAccountLinkService,
isFormDisabled as isFormDisabledSelector,
} from 'calypso/state/login/selectors';
import { isPartnerSignupQuery, isRegularAccount } from 'calypso/state/login/utils';
import {
isPartnerSignupQuery,
isPasswordlessAccount,
isRegularAccount,
} from 'calypso/state/login/utils';
import { getCurrentOAuth2Client } from 'calypso/state/oauth2-clients/ui/selectors';
import getCurrentQueryArguments from 'calypso/state/selectors/get-current-query-arguments';
import getCurrentRoute from 'calypso/state/selectors/get-current-route';
Expand Down Expand Up @@ -87,6 +91,7 @@ export class LoginForm extends Component {
currentQuery: PropTypes.object,
hideSignupLink: PropTypes.bool,
isSignupExistingAccount: PropTypes.bool,
sendMagicLoginLink: PropTypes.func,
};

state = {
Expand Down Expand Up @@ -192,7 +197,12 @@ export class LoginForm extends Component {
}

isUsernameOrEmailView() {
const { hasAccountTypeLoaded, socialAccountIsLinking } = this.props;
const { accountType, hasAccountTypeLoaded, socialAccountIsLinking, isSignupExistingAccount } =
this.props;

if ( isSignupExistingAccount && hasAccountTypeLoaded ) {
return isPasswordlessAccount( accountType );
}

return (
! socialAccountIsLinking &&
Expand Down Expand Up @@ -250,6 +260,10 @@ export class LoginForm extends Component {
return;
}

if ( isPasswordlessAccount( this.props.accountType ) ) {
this.props.sendMagicLoginLink?.();
}

this.loginUser();
};

Expand Down
48 changes: 8 additions & 40 deletions client/blocks/signup-form/passwordless.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -106,47 +106,15 @@ class PasswordlessSignupForm extends Component {
this.submitTracksEvent( false, { action_message: error.message, error_code: error.error } );

if ( [ 'already_taken', 'already_active', 'email_exists' ].includes( error.error ) ) {
const email = typeof this.state.email === 'string' ? this.state.email.trim() : '';
const response = await wpcom.req.get(
`/users/${ encodeURIComponent( email ) }/auth-options`
page(
addQueryArgs(
{
email_address: this.state.email,
is_signup_existing_account: true,
},
this.props.logInUrl
)
);
// Just for https://github.com/Automattic/wp-calypso/pull/83249. Passwordless accounts will be changed to facilitate emailing the login link.
if ( ! response?.passwordless ) {
page(
addQueryArgs(
{
email_address: this.state.email,
is_signup_existing_account: true,
},
this.props.logInUrl
)
);
return;
}

const errorMessage = (
<>
{ this.props.translate( 'An account with this email address already exists.' ) }
&nbsp;
{ this.props.translate( '{{a}}Log in now{{/a}} to finish signing up.', {
components: {
a: (
<a
href={ `${ this.props.logInUrl }&email_address=${ encodeURIComponent(
this.state.email
) }` }
/>
),
},
} ) }
</>
);

this.setState( {
errorMessages: [ errorMessage ],
isSubmitting: false,
} );

return;
}

Expand Down

0 comments on commit 7606242

Please sign in to comment.