Skip to content

Commit

Permalink
Update signup.html
Browse files Browse the repository at this point in the history
  • Loading branch information
ananyag309 authored Oct 11, 2024
1 parent afac803 commit e938935
Showing 1 changed file with 43 additions and 0 deletions.
43 changes: 43 additions & 0 deletions SignUp/signup.html
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,19 @@ <h1>Create Your Account</h1>
</div>
<button type="submit" class="signup-button">Sign Up</button>
</form>
<div class="or-divider">
<span>OR</span>
</div>
<button id="google-signup" class="google-signup-button">
<img src="../images/google-icon.png" alt="Google Icon" class="google-icon">
Sign up with Google
</button>
<div class="links">
<a href="../login/login.html"><u>Already have an account? Login</u></a>
</div>
</div>

<script src="https://accounts.google.com/gsi/client" async defer></script>
<script>
const signup = document.querySelector(".signup-button");

Expand Down Expand Up @@ -82,6 +90,41 @@ <h1>Create Your Account</h1>
console.log(err.message)
}
}

// Add Google Sign-In
function handleCredentialResponse(response) {
// Send the token to your server to verify and create a session
const token = response.credential;
// You should implement a function to handle the token on your server
signUpWithGoogle(token);
}

window.onload = function () {
google.accounts.id.initialize({
client_id: 'YOUR_GOOGLE_CLIENT_ID', // Replace with your actual Google Client ID
callback: handleCredentialResponse
});
google.accounts.id.renderButton(
document.getElementById("google-signup"),
{ theme: "outline", size: "large", width: "100%" }
);
};

async function signUpWithGoogle(token) {
try {
const res = await fetch("http://localhost:5000/auth/google-signup", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ token })
});

const data = await res.json();
console.log(data);
window.location.href = "http://127.0.0.1:5500/Collect-your-GamingTools/login/login.html";
} catch (err) {
console.log(err.message);
}
}
</script>
</body>
</html>

0 comments on commit e938935

Please sign in to comment.