Auth0 Google Registration Fails When User Name Contains White Space

Overview

Auth0 generates an invalid redirect_url error during Google social registration when a user's first or last name contains white spaces. This occurs because the generated redirect URL includes unencoded space characters. Apply the encodeURIComponent() function to the user's name attributes to properly format the URL and resolve the issue.

Applies To
  • Auth0
  • Social Connections (Google)
  • User Registration
  • Redirect URLs
Cause

The error occurs because the generated redirect URL provided by the Google connection contains unencoded white spaces derived from the user's first or last name.

Solution

To resolve the invalid redirect URL error, modify the application code to URL-encode the user's first and last name attributes by following these steps:

 
  1. Locate the application code responsible for generating the redirect URL after a successful Google registration.
  2. Apply the encodeURIComponent() function to the given_name and family_name variables to ensure that white spaces are converted to valid URL characters.
  3. Update the redirect URL assignment to use the encoded values.
const redirectUrl = `https://myapp.com/welcome?first_name=${encodeURIComponent(user.given_name)}&last_name=${encodeURIComponent(user.family_name)}`;
 
  1. Save and deploy the updated application code.

Related References

Recommended content

No recommended content found...