-
Notifications
You must be signed in to change notification settings - Fork 3
/
nuke-data.js
69 lines (59 loc) · 2.11 KB
/
nuke-data.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
const firebaseConfig = {
appId: "",
apiKey: "AIzaSyA5Hvh075ARg0wPQJmbVkIJBp0zlPkVG8M",
authDomain: "bluebubblemessaging-dev.firebaseapp.com",
databaseURL: "https://bluebubblemessaging-dev-default-rtdb.firebaseio.com",
projectId: "bluebubblemessaging-dev",
storageBucket: "bluebubblemessaging-dev.appspot.com",
messagingSenderId: "279611981758",
};
// Initialize Firebase
firebase.initializeApp(firebaseConfig);
// Login function
function login() {
const email = document.getElementById('email').value;
const confirmation = confirm(`Delete info for ${email}?`)
if (!confirmation) return
const password = document.getElementById('password').value;
firebase.auth().signInWithEmailAndPassword(email, password)
.catch((error) => {
const errorCode = error.code;
const errorMessage = error.message;
console.error("Login failed:", errorMessage);
alert("Login failed:", errorMessage)
});
}
let accounts = []
// Check for authentication state changes
firebase.auth().onAuthStateChanged((user) => {
if (!user) {
console.log("User is signed out");
return
}
const confirmation = confirm(`Delete info for ${user.email}?`)
if (!confirmation) return
document.getElementById('loginForm').style.display = 'none';
// User is signed in, execute the code inside the .then block
console.log("Logged in as:", user.email);
const userId = user.uid;
const dbRef = firebase.database().ref(`users/${userId}`);
dbRef.on('value', (snapshot) => {
const data = snapshot.val();
if (!data) return
const pretty = JSON.stringify(data, null, 2);
console.log('user value', pretty)
accounts = Object.keys(data.accounts)
deleteAccount(accounts[0])
firebase.database().ref(`users/${userId}`).remove();
document.getElementById('status').innerHTML = 'Nuked user data';
});
})
function deleteAccount(accountId) {
const dbRef = firebase.database().ref(`accounts/${accountId}`);
dbRef.on('value', (snapshot) => {
const data = snapshot.val();
if (!data) return
dbRef.remove()
document.getElementById('status').innerHTML = 'Nuked user & account data';
});
}