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

54 lines
1.2 KiB
JavaScript

import { makeAutoObservable } from "mobx";
import api from "../api";
import history from "../history";
import { combineUrl, isAdmin } from "../utils";
class TfaStore {
tfaSettings = null;
constructor() {
makeAutoObservable(this);
}
getTfaSettings = async () => {
const res = await api.settings.getTfaSettings();
const sms = res[0].enabled;
const app = res[1].enabled;
const type = sms ? "sms" : app ? "app" : "none";
this.tfaSettings = type;
return type;
};
setTfaSettings = async (type) => {
const res = await api.settings.setTfaSettings(type);
this.getTfaConfirmLink(res, type);
};
getTfaConfirmLink = async (res, type) => {
if (res && type !== "none") {
const link = await api.settings.getTfaConfirmLink();
document.location.href = link;
}
};
getSecretKeyAndQR = async (confirmKey) => {
return api.settings.getTfaSecretKeyAndQR(confirmKey);
};
loginWithCode = async (userName, passwordHash, code) => {
return api.user.loginWithTfaCode(userName, passwordHash, code);
};
getBackupCodes = async () => {
return api.settings.getTfaNewBackupCodes();
};
unlinkApp = async () => {
return api.settings.unlinkTfaApp();
};
}
export default TfaStore;