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
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>