Auth0 Google Registration Fails When User Name Contains White Space
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.
- Auth0
- Social Connections (Google)
- User Registration
- Redirect URLs
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.
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:
- Locate the application code responsible for generating the redirect URL after a successful Google registration.
- Apply the
encodeURIComponent()function to thegiven_nameandfamily_namevariables to ensure that white spaces are converted to valid URL characters. - 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)}`;
- Save and deploy the updated application code.