Checkout Extension -- force customer login for specific customers

Solved

Checkout Extension -- force customer login for specific customers

Schmidtc63
Shopify Partner
98 14 27

On checkout, I need to be able to force login for specific customers based on the email address they provide:

 

		let currentEmail = buyerIdentity?.email.current;
		buyerIdentity?.email.subscribe(async (newEmail) => {
			needsLogin = -1;
			console.log(`email address changed: `, newEmail);
			currentEmail = newEmail;
			needsLogin = +(await checkForceLogin(currentEmail));
			console.log(`needs Login: `, needsLogin);
			if (needsLogin > 0) {
				displayErrorBanner(
					root,
					"This email account requires you to log in."
				);
			}
		});

 

Instead of displaying an error banner, I'd like to have a modal that contains a login form.

And then the next step is how do I validate the customer based on their input?

 

Thank you!

Chris

 

Accepted Solution (1)
Schmidtc63
Shopify Partner
98 14 27

This is an accepted solution.

No. Not even close. I'm not trying to trap their login. I'm trying to force a login if the customer email meets certain criteria.

 

  • The checkout extension does not allow auto-popup modals. The user has to take some action -- a click -- to show a modal.
  • buyerJourney somewhat handles this. Since we can't do a popup, the code simply displays an error banner and asks the customer to log in via the login link on the checkout page. 

 

    buyerJourney.intercept(
      async () => {
        if (currentEmail !== buyerIdentity?.email.current) {
          currentEmail = buyerIdentity?.email.current;
          needsLogin = +(await checkForceLogin(currentEmail));
        }
        let returnBehavior = {
          behavior: `allow`,
        };
        if (needsLogin > 0) {
          returnBehavior = {
            behavior: `block`,
            reason: `Special Pricing and/or Net Payment`,
            errors: [
              {
                message:
                  `This account requires you to log in.`,
              },
            ],
          };
        }
.
.
.
});

 

View solution in original post

Replies 2 (2)

muhammadsalmank
Shopify Partner
26 1 4

Hi,

just make an sqlite DB in server. and connect your app with it and when ever they tried to login use endpoints from your server and verify it.

you need more help?

Schmidtc63
Shopify Partner
98 14 27

This is an accepted solution.

No. Not even close. I'm not trying to trap their login. I'm trying to force a login if the customer email meets certain criteria.

 

  • The checkout extension does not allow auto-popup modals. The user has to take some action -- a click -- to show a modal.
  • buyerJourney somewhat handles this. Since we can't do a popup, the code simply displays an error banner and asks the customer to log in via the login link on the checkout page. 

 

    buyerJourney.intercept(
      async () => {
        if (currentEmail !== buyerIdentity?.email.current) {
          currentEmail = buyerIdentity?.email.current;
          needsLogin = +(await checkForceLogin(currentEmail));
        }
        let returnBehavior = {
          behavior: `allow`,
        };
        if (needsLogin > 0) {
          returnBehavior = {
            behavior: `block`,
            reason: `Special Pricing and/or Net Payment`,
            errors: [
              {
                message:
                  `This account requires you to log in.`,
              },
            ],
          };
        }
.
.
.
});