updated danger zone popups when using google sign in

This commit is contained in:
Miodec 2021-07-19 19:05:24 +01:00
parent 1a9d5d4acf
commit ab5ecb195a
2 changed files with 71 additions and 43 deletions

View file

@ -14,7 +14,7 @@ import * as DB from "./db";
import * as TestLogic from "./test-logic";
import * as UI from "./ui";
const gmailProvider = new firebase.auth.GoogleAuthProvider();
export const gmailProvider = new firebase.auth.GoogleAuthProvider();
const githubProvider = new firebase.auth.GithubAuthProvider();
export function signIn() {

View file

@ -49,7 +49,12 @@ class SimplePopup {
this.initInputs();
el.find(".button").text(this.buttonText);
if (!this.buttonText) {
el.find(".button").remove();
} else {
el.find(".button").text(this.buttonText);
}
// }
}
@ -160,51 +165,55 @@ list.updateEmail = new SimplePopup(
],
"",
"Update",
(pass, email, emailConfirm) => {
async (password, email, emailConfirm) => {
try {
const user = firebase.auth().currentUser;
const credential = firebase.auth.EmailAuthProvider.credential(
user.email,
pass
);
if (email !== emailConfirm) {
Notifications.add("Emails don't match", 0);
return;
}
if (user.providerData[0].providerId === "password") {
const credential = firebase.auth.EmailAuthProvider.credential(
user.email,
password
);
await user.reauthenticateWithCredential(credential);
}
Loader.show();
user
.reauthenticateWithCredential(credential)
.then(() => {
CloudFunctions.updateEmail({
uid: user.uid,
previousEmail: user.email,
newEmail: email,
}).then((data) => {
Loader.hide();
if (data.data.resultCode === 1) {
Notifications.add("Email updated", 0);
setTimeout(() => {
AccountController.signOut();
}, 1000);
} else if (data.data.resultCode === -1) {
Notifications.add("Current email doesn't match", 0);
} else {
Notifications.add(
"Something went wrong: " + JSON.stringify(data.data),
-1
);
}
});
})
.catch((e) => {
Loader.hide();
Notifications.add("Incorrect current password", -1);
});
CloudFunctions.updateEmail({
uid: user.uid,
previousEmail: user.email,
newEmail: email,
}).then((data) => {
Loader.hide();
if (data.data.resultCode === 1) {
Notifications.add("Email updated", 0);
setTimeout(() => {
AccountController.signOut();
}, 1000);
} else if (data.data.resultCode === -1) {
Notifications.add("Current email doesn't match", 0);
} else {
Notifications.add(
"Something went wrong: " + JSON.stringify(data.data),
-1
);
}
});
} catch (e) {
Notifications.add("Something went wrong: " + e, -1);
}
},
() => {}
() => {
const user = firebase.auth().currentUser;
if (user.providerData[0].providerId === "google.com") {
eval(`this.inputs = []`);
eval(`this.buttonText = undefined`);
eval(
`this.text = "You can't change your email when using Google Authentication";`
);
}
}
);
list.updatePassword = new SimplePopup(
@ -251,7 +260,16 @@ list.updatePassword = new SimplePopup(
Notifications.add(e, -1);
}
},
() => {}
() => {
const user = firebase.auth().currentUser;
if (user.providerData[0].providerId === "google.com") {
eval(`this.inputs = []`);
eval(`this.buttonText = undefined`);
eval(
`this.text = "You can't change your password when using Google Authentication";`
);
}
}
);
list.clearTagPb = new SimplePopup(
@ -327,12 +345,16 @@ list.resetPersonalBests = new SimplePopup(
async (password) => {
try {
const user = firebase.auth().currentUser;
const credential = firebase.auth.EmailAuthProvider.credential(
user.email,
password
);
if (user.providerData[0].providerId === "password") {
const credential = firebase.auth.EmailAuthProvider.credential(
user.email,
password
);
await user.reauthenticateWithCredential(credential);
} else if (user.providerData[0].providerId === "google.com") {
await user.reauthenticateWithPopup(AccountController.gmailProvider);
}
Loader.show();
await user.reauthenticateWithCredential(credential);
let resetResult = await CloudFunctions.resetPersonalBests({
uid: firebase.auth().currentUser.uid,
});
@ -353,7 +375,13 @@ list.resetPersonalBests = new SimplePopup(
Notifications.add(e, -1);
}
},
() => {}
() => {
const user = firebase.auth().currentUser;
if (user.providerData[0].providerId === "google.com") {
eval(`this.inputs = []`);
eval(`this.buttonText = "Reauthenticate to reset"`);
}
}
);
list.resetSettings = new SimplePopup(