-
Notifications
You must be signed in to change notification settings - Fork 0
/
Firebase.js
44 lines (36 loc) · 1.51 KB
/
Firebase.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
import * as firebase from "firebase";
// Does some checking and updates user email if all checks passed
export const changeUserEmail = async (oldEmail, newEmail, confirmEmail) => {
const user = firebase.auth().currentUser;
let result = {error: null};
if (oldEmail.includes(user.email)) {
if (newEmail === confirmEmail) {
await user.updateEmail(newEmail)
.catch((error) => result.error = error.message);
}
else result.error = 'Please ensure your new email matches the confirmation email';
}
else result.error = 'Your old email does not match with our records';
return result;
}
// Does some checking and updates user password if all checks passed
export const changeUserPassword = async (newPassword, confirmPassword) => {
const user = firebase.auth().currentUser;
let result = {error: null};
if (newPassword === confirmPassword) {
await user.updatePassword(newPassword)
.catch((error) => result.error = error.message);
console.log('Pass updated');
}
else result.error = 'Please ensure your new password matches the confirmation password';
return result;
}
// DANGER ZONE: Deletes a user from firebase
export const deleteUser = async () => {
const user = firebase.auth().currentUser;
let result = {error: null};
// Disabled for the time being, but it works :D
// await user.delete().catch((error) => result.error = error.message);
console.log('Deleted user: ' + user.email);
return result;
}