Introduction
Enabling social login on your WordPress + WooCommerce site improves user experience and boosts sign-ups. This tutorial will guide you through setting up Google, Facebook, and Apple login, automatically creating accounts, and handling user sessions.
Step 1: Install a Social Login Plugin

To integrate social login easily, install a plugin like Nextend Social Login or Super Socializer.
Installing Nextend Social Login
- Go to your WordPress Admin Dashboard.
- Navigate to Plugins > Add New.
- Search for Nextend Social Login.
- Click Install Now, then Activate.
Step 2: Configure Social Login Providers
You need to set up API credentials for Google, Facebook, and Apple.
Google Login Setup
- Go to Google Cloud Console.
- Create a new project and enable Google Identity Platform.
- Under Credentials, create an OAuth 2.0 Client ID.
- Set the Authorized Redirect URI to:
https://yourwebsite.com/wp-login.php?action=wordpress_social_auth
- Copy and paste the Client ID and Client Secret into the Nextend Social Login settings.
Facebook Login Setup
- Go to Facebook Developers.
- Create a new Facebook App.
- Enable Facebook Login.
- Set the Valid OAuth Redirect URIs to:
https://yourwebsite.com/wp-login.php?action=wordpress_social_auth
- Copy the App ID and App Secret into the Nextend Social Login settings.
Apple Login Setup
- Go to Apple Developer.
- Create a new Service ID under Certificates, Identifiers & Profiles.
- Enable Sign in with Apple.
- Set the Redirect URI to:
https://yourwebsite.com/wp-login.php?action=wordpress_social_auth
- Generate a Private Key, then add it to Nextend Social Login.
Step 3: Configure Automatic Account Creation
Once social login is enabled, you need to automatically create user accounts.
- In Nextend Social Login > Settings, enable:
- User creation on first login
- Email verification (optional)
- Under WooCommerce > Settings > Accounts & Privacy, enable:
- “Allow customers to create an account during checkout”
- “When creating an account, automatically generate an account password”
Now, when a user logs in via social login, their account is created automatically.
Step 4: Manage User Sessions
Using JWT Authentication for WordPress
To keep users logged in securely, install JWT Authentication for WP REST API.
Installing the Plugin
- Go to Plugins > Add New.
- Search for JWT Authentication for WP REST API.
- Install and activate the plugin.
Configuring JWT Authentication
- Edit your wp-config.php file and add:
define('JWT_AUTH_SECRET_KEY', 'your-secret-key'); define('JWT_AUTH_CORS_ENABLE', true);
- Now, whenever a user logs in via social login, they can receive a JWT token.
- Send a request to authenticate:
curl -X POST https://yourwebsite.com/wp-json/jwt-auth/v1/token \ -H "Content-Type: application/json" \ -d '{"username":"user_email","password":"random_password"}'
- Use this token to authenticate future API requests.
Step 5: Testing and Debugging
- Try logging in with Google, Facebook, or Apple.
- Check if the user is automatically created.
- Verify that sessions persist.
- If issues arise, check OAuth settings and redirect URIs.
Conclusion
With social login, users can register and log in quickly and securely. By integrating JWT authentication, you ensure seamless sessions across your site. Try this setup to improve user experience and boost conversions!