Implement Social Login
PWA Kit comes out of the box with the option to use social login for your shoppers. Include the feature in your Progressive Web App (PWA) Kit site to improve the shopper experience. With social login, shoppers can quickly log into your site and create profiles by using their social network accounts.
Our demo site shows the default implementation of social login.
To enable and configure social login for your PWA Kit site, follow the steps in this guide. Throughout this guide we use an example storefront with the URL: https://www.example.com
. Replace example.com
with your domain name.
Social login isn't supported in hybrid storefronts.
PWA Kit supports the identity providers (IdPs) listed under Supported Identity Providers.
If you meet the prerequisites, the Google and Apple social logins are available in the Retail React App by default.
To use social login:
- Build your site using Composable Storefront and Retail React App version 6.0 or later.
- To add your chosen IdP, complete the steps in Registering an Identity Provider.
- Configure a Shopper Login and API Access (SLAS) Client. In your client’s Redirect URI field, enter the redirect URI that you want to use in the social login flow. By default, PWA Kit uses
/social-callback
as the path. For example, if your domain isexample.com
, enter:https://www.example.com/social-callback
. Replaceexample.com
with your actual domain.
a. Update template-retail-react-app/config/default.js
To configure social login in your PWA Kit project, update template-retail-react-app/config/default.js
as shown in this example.
Ensure that the redirect URI path configured in your PWA Kit project matches the path configured in your SLAS client. The SLAS client can use a wildcard for the full URI, but the paths must match exactly.
b. Optional: Use an Environment Variable to Set the Redirect URI
The value of the environment variable for social login overrides any values that you added in template-retail-react-app/config/default.js
.
Optionally, you can set the redirect URI using an environment variable instead of template-retail-react-app/config/default.js
. Use template-retail-react-app/config/default.js
to enable social login and set the IdPs. Configure this environment variable to set the redirect URI.
SOCIAL_LOGIN_REDIRECT_URI
By default, PWA Kit imports and configures the icons for the Google and Apple social logins in the SocialLogin
component in the template-retail-react-app/app/components/social-login/index.jsx
file. On your site, you can include icons for other supported IdPs. To do so, complete these steps.
a. Import Icons into the SocialLogin
Component
In this example, we import the Facebook icon into the SocialLogin
component.
b. Extend the IDP_CONFIG
Object
Use the IDP_CONFIG
object in the SocialLogin
component to display buttons for your additional social logins, each with their respective icons and localized messages.
In this example, we add the configuration for Facebook. Ensure that each IdP key matches the lowercase name of your chosen IdP.
- Follow security best practices to protect shopper accounts. For example:
- If you’re using embedded CDN (eCDN), you can apply eCDN Rate Limiting Rules.
- If you’re using a third-party content delivery network (CDN) such as Cloudfare, you can Block requests by Threat Score.
- Track shopper usage of authentication options and diagnose issues efficiently. For example, use Log Center to access logs from Managed Runtime (MRT) and your B2C Commerce instance.
- Merge Shopper Profiles in Shopper Login and API Access Service (SLAS) to ensure that shoppers with both a B2C Commerce identity and a third-party IdP can log in seamlessly without creating duplicate accounts.
- If both profiles exist before you configured
loginMergeClaims
and before a shopper logged into your site, no merge is performed. Accounts can't be merged retroactively. - The steps in the Merge Shopper Profiles guide apply to shoppers who have the same login ID for their B2C Commerce profile and a third-party IdP.
For more details about merging profiles and the supported use cases, see Merge Shopper Profiles.
This section provides suggested solutions for a few common errors that you can encounter related to social login.
Potential Cause: The social login configuration is incorrect.
Suggested Solution: Ensure that the redirect URI path configured in your PWA Kit project matches the path configured in your SLAS client. See Configure Social Login.
Potential Cause: Shoppers have separate profiles for B2C Commerce and third-party IdPs.
Suggested Solution: Follow the steps in Merge Shopper Profiles to merge records for shoppers registered with B2C Commerce and a third-party IdP.