-
Notifications
You must be signed in to change notification settings - Fork 2
/
db.js
69 lines (62 loc) · 2.67 KB
/
db.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
67
68
69
// Initialize Firebase
firebase.initializeApp({
apiKey: "AIzaSyB3FDjwLrfTfSBWRo4-z_S5o9D1rFh8ulU",
authDomain: "synco-c1c21.firebaseapp.com",
databaseURL: "https://synco-c1c21.firebaseio.com",
projectId: "synco-c1c21",
storageBucket: "synco-c1c21.appspot.com",
messagingSenderId: "333441973483"
});
// Initialize Cloud Firestore through Firebase
var db = firebase.firestore();
// Disable deprecated features
db.settings({
timestampsInSnapshots: true
});
var user = firebase.auth().currentUser;
function signup() {
var newUsername = document.getElementById("new-account-uname").value;
var newPassword = document.getElementById("new-account-pword").value;
//firebase.database().ref().child("profiles").push({
// username: newUsername
//});
firebase.auth().createUserWithEmailAndPassword(newUsername + "@fakeemail.com", newPassword).then(function() {
window.location.href = "https://synco.tk";
}).catch(function(error) {
alert(error)
});
user = firebase.auth().currentUser;
}
function signin() {
var uname = document.getElementById("signin-uname").value;
var password = document.getElementById("signin-password").value;
firebase.auth().signInWithEmailAndPassword(uname + "@fakeemail.com", password).then(function() {
user = firebase.auth().currentUser;
window.location.href = "https://synco.tk";
}).catch(function(error) {
alert(error);
});
}
function signout() {
firebase.auth().signOut().then(function() {
console.log("signed out");
}).catch(function(error) {
console.log(error);
});
}
firebase.auth().onAuthStateChanged(function(user) {
setInterval(function () {
if (firebase.auth().currentUser) {
if (localStorage.name !== user.email.replace("@fakeemail.com", "")) {
signout()
}
}
}, 100)
if(user) {
document.getElementById("navbar-username").innerHTML = "<div class='dropdown' style='float: right'><a class='toggle-dropdown'>" + user.email.replace("@fakeemail.com", "") + "</a><ul style='right: 0px; color: gray; max-height: 100px; margin: 20px 10px;'><li onclick='window.location.href = \"?edit\";'>Make a New Story</li><li onclick='window.location.href = \"?mystories\"'>My Stories</li><li onclick='signout()'>Logout</li></ul>";
localStorage.name = user.email.split("@")[0];
} else {
document.getElementById("navbar-username").innerHTML = "<button class='btn-primary' style='background-color: white; margin: 0; font-size: 100%;'><a href=\"index.html?login\" style='color: tomato'>Login</a></button> <button class='btn-primary' style='background-color: white; margin: 0; font-size: 100%;'><a href='index.html?signup' style='color: tomato'>Signup</a></button>";
localStorage.name = "";
}
});