forked from meenakshiiyer2531/Rubik-Cube
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript1.js
22 lines (20 loc) · 900 Bytes
/
script1.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
function handleCredentialResponse(response)//is the callback function that handles the ID token received from Google.
{
const data = jwt_decode(response.credential);
console.log('User data:', data);
// Display user data or perform your login logic here
document.body.innerHTML = `
<h1>Welcome, ${data.name}</h1>
<p>Email: ${data.email}</p>
<img src="${data.picture}" alt="Profile Picture">
`;
}
function jwt_decode(token) //jwt_decode is a helper function to decode the JWT token received from Google to extract user information.
{
const base64Url = token.split('.')[1];
const base64 = base64Url.replace(/-/g, '+').replace(/_/g, '/');
const jsonPayload = decodeURIComponent(atob(base64).split('').map(function(c) {
return '%' + ('00' + c.charCodeAt(0).toString(16)).slice(-2);
}).join(''));
return JSON.parse(jsonPayload);
}