onSignInSuccess()

in packages/fxa-content-server/app/scripts/views/mixins/signin-mixin.js [170:281]


  onSignInSuccess(account) {
    if (!account.get('verified')) {
      const verificationMethod = account.get('verificationMethod');
      const verificationReason = account.get('verificationReason');

      // with React conversion, we are deprecating the confirm_signin view in favor of 'signin_token_code'
      if (
        (verificationReason === VerificationReasons.SIGN_IN &&
          verificationMethod === VerificationMethods.EMAIL) ||
        (verificationReason === VerificationReasons.CHANGE_PASSWORD &&
          verificationMethod === VerificationMethods.EMAIL)
      ) {
        return this.navigate('confirm_signin', { account });
      }

      if (
        (verificationReason === VerificationReasons.SIGN_IN &&
          verificationMethod === VerificationMethods.EMAIL_OTP) ||
        (verificationReason === VerificationReasons.CHANGE_PASSWORD &&
          verificationMethod === VerificationMethods.EMAIL_OTP)
      ) {
        if (this.isInPushLoginExperiment()) {
          return this.navigate('/push/send_login');
        }

        return this.navigate('signin_token_code', { account });
      }

      if (
        (verificationReason === VerificationReasons.SIGN_IN &&
          verificationMethod === VerificationMethods.TOTP_2FA) ||
        (verificationReason === VerificationReasons.CHANGE_PASSWORD &&
          verificationMethod === VerificationMethods.TOTP_2FA)
      ) {
        return this.navigate('signin_totp_code', { account });
      }

      if (
        verificationReason === VerificationReasons.SIGN_UP &&
        verificationMethod === VerificationMethods.EMAIL_OTP
      ) {
        return this.navigate('confirm_signup_code', { account });
      }

      if (
        verificationReason === VerificationReasons.SIGN_UP &&
        typeof verificationMethod === 'undefined'
      ) {
        // cached signin with an unverified account. A code
        // is not re-sent automatically, so send a new one
        // and then go to the confirm screen.
        return account.verifySessionResendCode().then(() => {
          this.navigate('confirm_signup_code', { account });
        });
      }
      // with React conversion, we are deprecating the default confirm_signin view in favor of 'signin_token_code'
      return this.navigate('confirm', { account });
    }

    // If the account's uid changed, update the relier model or else
    // the user can end up in a permanent "Session Expired" state
    // when signing into Sync via force_auth. This occurs because
    // Sync opens force_auth with a uid. The uid could have changed. We
    // sign the user in here with the new uid, then attempt to do
    // other operations with the old uid. Not all brokers support
    // uid changes, so only make the update if the broker supports
    // the change. See #3057 and #3283
    if (
      account.get('uid') !== this.relier.get('uid') &&
      this.broker.hasCapability('allowUidChange')
    ) {
      this.relier.set('uid', account.get('uid'));
    } else if (account.get('email') !== this.relier.get('email')) {
      // if the broker does not support `allowUidChange`, we still
      // need to update `email` and `uid` otherwise login will fail
      // for a deleted account. See #4316
      this.relier.set('email', account.get('email'));
      this.relier.set('uid', account.get('uid'));
    }

    if (account.get('metricsEnabled') === false) {
      GleanMetrics.setEnabled(false);
    }

    GleanMetrics.login.success();

    // This is the generic signin.success metric. The one
    // true signin success metric.
    this.logEvent('signin.success');

    // This event is emitted whenever a user skips login
    // confirmation, whether it was required or not.
    this.logEvent('signin.success.skip-confirm');

    // This event ties the signin success to a screen.
    // Currently, can be oauth, signin, signup, signin-unblock
    this.logViewEvent('signin.success');

    const brokerMethod = this.afterSignInBrokerMethod || 'afterSignIn';
    const navigateData = this.afterSignInNavigateData || {};

    if (this.relier.get('redirectTo')) {
      // If `redirectTo` is specified, override the default behavior and
      // redirect to the requested page.
      const behavior = new NavigateBehavior(this.relier.get('redirectTo'));
      this.relier.unset('redirectTo');
      this.broker.setBehavior(brokerMethod, behavior, navigateData);
    }

    // Brokers handle all next steps.
    return this.invokeBrokerMethod(brokerMethod, account);
  },