-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
53 lines (47 loc) · 1.61 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
<!DOCTYPE html>
<html>
<script src="https://www.gstatic.com/firebasejs/3.0.5/firebase.js"></script>
<script src="init.js"></script>
<script src="https://apis.google.com/js/platform.js" async defer></script>
<meta name="google-signin-client_id" content="568327038315-5gc1eovtfcrgpco0sumpbhfaffhi93ja.apps.googleusercontent.com">
<script>
firebase.initializeApp(config);
</script>
<script type= "text/javascript">
function onSignIn(googleUser) {
var unsubscribe = firebase.auth().onAuthStateChanged(function(firebaseUser) {
unsubscribe();
if (!isUserEqual(googleUser, firebaseUser)) {
var credential = firebase.auth.GoogleAuthProvider.credential(
googleUser.getAuthResponse().id_token);
firebase.auth().signInWithCredential(credential).catch(function(error) {
var errorCode = error.code;
var errorMessage = error.message;
var email = error.email;
var credential = error.credential;
console.log(error);
});
//
} else {
console.log('User already signed-in Firebase.');
location.replace(ENTRY);
}
});
}
function isUserEqual(googleUser, firebaseUser) {
if (firebaseUser) {
var providerData = firebaseUser.providerData;
for (var i = 0; i < providerData.length; i++) {
if (providerData[i].providerId === firebase.auth.GoogleAuthProvider.PROVIDER_ID &&
providerData[i].uid === googleUser.getBasicProfile().getId()) {
return true;
}
}
}
return false;
}
</script>
<head>
<div class="g-signin2" data-onsuccess="onSignIn"></div>
</head>
</html>