DocSpace-client/packages/asc-web-common/store/TfaStore.js

52 lines
1.2 KiB
JavaScript
Raw Normal View History

2021-05-05 11:59:08 +00:00
import { makeAutoObservable } from "mobx";
import api from "../api";
2021-05-12 09:10:08 +00:00
import history from "../history";
import { combineUrl, isAdmin } from "../utils";
2021-05-05 11:59:08 +00:00
class TfaStore {
tfaSettings = null;
backupCodes = null;
constructor() {
makeAutoObservable(this);
}
2021-05-07 11:22:21 +00:00
getTfaSettings = async () => {
console.log("getTfaSettings");
const res = await api.settings.getTfaSettings();
const sms = res[0].enabled;
const app = res[1].enabled;
2021-05-07 11:32:00 +00:00
const type = sms ? "sms" : app ? "app" : "none";
this.tfaSettings = type;
return type;
2021-05-07 11:22:21 +00:00
};
2021-05-05 11:59:08 +00:00
setTfaSettings = async (type) => {
console.log("setTfaSettings");
const res = await api.settings.setTfaSettings(type);
console.log(res);
2021-05-07 11:32:00 +00:00
this.getTfaConfirmLink(res, type);
};
getTfaConfirmLink = async (res, type) => {
console.log("getTfaConfirmLink");
2021-05-05 11:59:08 +00:00
if (res && type !== "none") {
const link = await api.settings.getTfaConfirmLink();
console.log(link);
2021-05-12 09:10:08 +00:00
document.location.href = link;
2021-05-05 11:59:08 +00:00
}
};
getBackupCodes = async () => {
console.log("getBackupCodes");
const backupCodes = await api.settings.getTfaNewBackupCodes();
console.log(backupCodes);
this.backupCodes = backupCodes;
};
}
export default TfaStore;