-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
54 lines (44 loc) · 1.22 KB
/
app.js
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
54
// Initialize Firebase
var config = {
apiKey: "AIzaSyCJlEMeaDXhGRe7AFdeUd-_dHrTKd75Ah4",
authDomain: "prueba-8358a.firebaseapp.com",
databaseURL: "https://prueba-8358a.firebaseio.com",
projectId: "prueba-8358a",
storageBucket: "prueba-8358a.appspot.com",
messagingSenderId: "876058746890"
};
firebase.initializeApp(config);
var user = null;
var $logGoo = $('#google');
$logGoo.on('click', googleLog);
function googleLog(event) {
event.preventDefault();
var provider = new firebase.auth.GoogleAuthProvider();
firebase
.auth()
.signInWithPopup(provider)
.then(function (result) {
var user = firebase.auth().currentUser;
name = user.displayName;
console.log(user);
console.log(name);
if (user) {
window.location.href = 'views/discover';
}
})
}
function writeUserData(userId, name, email, imageUrl) {
firebase.database().ref('users/' + userId).set({
username: name,
email: email,
profile_picture: imageUrl
});
}
firebase.auth().onAuthStateChanged(function (user) {
if (user) {
// User is signed in.
writeUserData((user.providerData[0].uid), (user.displayName), (user.email), (user.photoURL));
} else {
// No user is signed in.
}
});