-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfirebaseActions.js
66 lines (58 loc) · 1.66 KB
/
firebaseActions.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
55
56
57
58
59
60
61
62
63
64
65
66
var database = firebase.database();
var user = firebase.auth().currentUser;
function test(){
alert ("write");
}
// function writeUserData() {
// firebase.auth().onAuthStateChanged(function(user) {
// if (user) {
// var user = firebase.auth().currentUser;
// var uName = document.getElementById("firstName");
// var ulName = document.getElementById("lastName");
// var about = document.getElementById("about");
// // alert(about.value);
// firebase.database().ref('users/' + user.uid).set({
// // username: name,
// email: user.email,
// name: uName.value,
// lastName: ulName.value,
// about: about.value,
// });
// }
//
// });
// }
function readUsers(){
var userId = firebase.auth().currentUser.uid;
return firebase.database().ref('/users/' + userId).once('value').then(function(snapshot) {
var username = (snapshot.val() && snapshot.val().about) || 'Anonymous';
alert(username);
// ...
});
}
// function logout(){
//
// if (firebase.auth().currentUser) {
// // [START signout]
// // var user = firebase.auth().currentUser
// // alert(user.email);
// firebase.auth().signOut();
// // alert ("signed out");
// window.location.href = "/login.html";
//
// // [END signout]
// }else{
// alert ("strange");
// window.location.href = "/index.html";
// }
// }
function logout(){
firebase.auth().signOut().then(function() {
alert ("You are now signed out");
window.location.href = "../gse5//index.html";
// Sign-out successful.
}).catch(function(error) {
alert ("error");
// An error happened.
});
}