forked from binary-riviera/GroupSoftwareFrontend
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlogOut.js
42 lines (35 loc) · 1 KB
/
logOut.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
/**
* A JavaScript file to handle log outs during the game
*
*
*
* @author Louis Evans.
* @since 20/2/2020
*/
const out = document.getElementById("exitGame");
// Handle when user attempts to leave the game
out.addEventListener('click', e => {
console.log('logging out')
firebase.auth().signOut().then(function() {
// Sign-out successful.
console.log("logged out")
var name = localStorage.getItem("studentName")
var len = localStorage.getItem("lengthFeed");
console.log(len);
firebase.database().ref().child('feed').update({
[len]:"Player " + name + " has left the game"
});
console.log('real time database updated with logging out');
}).catch(function(error) {
// An error happened.
var errorCode = error.code;
var errorMessage = error.message;
});
// check user is logged in
firebase.auth().onAuthStateChanged(firebaseUser => {
if (firebaseUser) {
} else {
document.location.href = "introPage.html";
}
});
});