forked from GitZChen/DroneBlocks-Web
-
Notifications
You must be signed in to change notification settings - Fork 0
/
firebase.html
52 lines (42 loc) · 1.39 KB
/
firebase.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
<html>
<head>
<script src="https://cdn.firebase.com/js/client/2.4.2/firebase.js"></script>
</head>
<body>
<script>
var ref = new Firebase("https://fiery-inferno-4972.firebaseio.com");
var display_name;
var google_id;
var profile_image
var isNewUser = true;
// Create a callback which logs the current auth state
function authDataCallback(authData) {
//
if (!authData) {
ref.authWithOAuthRedirect("google", function (error) {
document.write(error);
});
}
else {
display_name = authData.google.displayName;
google_id = authData.google.id;
profile_image = authData.google.profileImageURL;
document.write("Hello " + display_name + ",<br />your Google id is " + google_id + "<br />your Firebase id is " + authData.uid + " and this is your profile picture: <br /><br /><img src='" + profile_image + "' /><br /><br /><a href='#' onclick='saveData();'>Save Mission</a>");
console.log(authData);
}
}
ref.onAuth(authDataCallback);
function saveData() {
var ref = new Firebase("https://fiery-inferno-4972.firebaseio.com/droneblocks");
var usersRef = ref.child("users");
usersRef.push({
"google_id": google_id,
"google_display_name": display_name,
"google_profile_image": profile_image
});
}
</script>
<div>
</d>
</body>
</html>