Google Login API Won't Redirect After Signup

Hello Replit Community!

I’m attempting to test my Google API login functionality but I am unable to get it to redirect to my homepage after sign up. The API loads perfectly, the user is able to select their email and the Google login API popup successfully goes away. However, after signup it will not redirect to my homepage.

My project is not deployed yet. I’m using my development homepage URL. I included it in my Google Cloud Authorized redirect URIs.

My apologies in advance, I’m sure this is something really basic that I’m overlooking :person_facepalming:

Any help would be very much appreciated! Thank you!


<!DOCTYPE html>
<html>
<head>
    <title>Sign Up</title>
    <meta name="google-signin-client_id" content="YOUR_CLIENT_ID.apps.googleusercontent.com">
    <script src="https://apis.google.com/js/platform.js" async defer></script>
    <style>
        body {
            font-family: Arial, sans-serif;
            display: flex;
            justify-content: center;
            align-items: center;
            height: 100vh;
        }
        .container {
            text-align: center;
        }
    </style>
</head>
<body>
    <div class="container">
        <h2>Sign Up with Google</h2>
        <div class="g-signin2" data-onsuccess="onSignIn"></div>
        <a href="#" onclick="signOut();" style="display:none;" id="signout">Sign out</a>
    </div>

    <script>
        function onSignIn(googleUser) {
         
            // ...

            // Redirect after successful sign-in
            window.location.href = 'my development homepage URL'; 
        }

        function signOut() {
            var auth2 = gapi.auth2.getAuthInstance();
            auth2.signOut().then(function () {
                console.log('User signed out.');
                document.getElementById('signout').style.display = 'none';
            });
        }

        function startApp() {
            gapi.load('auth2', function(){
                gapi.auth2.init({
                    client_id: 'YOUR_CLIENT_ID.apps.googleusercontent.com'
                });
            });
        }

        window.onload = startApp;
    </script>
</body>
</html>

Hi @specificlook , welcome to the forums!

Could it be this bit that you need to change? To an actual route maybe?

This looks like the problem.

My homepage is included in my code, just left it out on this public post.

My client ID is included in my code, just left it out on this public post.

Is it in the JavaScript? If so, that’s a security risk. Anyone can get your client ID by inspecting your site.

It’s been turned into secret. The site is still private, it hasn’t been deployed yet which makes me feel as if there is a step I’m missing since it’s not deployed.

Really appreciate your help!

1 Like

The sign up page loads as well as the google login popup, but when I select an authorized test email, spins as if it logins in, the popup page goes away but it does not redirect to my homepage, it stays on the /signup.html page.