fix totp
This commit is contained in:
parent
d66cae805e
commit
13e437f2bd
|
@ -527,8 +527,12 @@ export class API {
|
|||
);
|
||||
const resp = await fetch(request);
|
||||
await checkResponse(resp);
|
||||
try {
|
||||
const data = (await resp.json()) as { data: NewTOTPResp };
|
||||
return data.data;
|
||||
} catch {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
async deleteTOTP(baseMount: string, name: string): Promise<void> {
|
||||
|
|
14
src/main.tsx
14
src/main.tsx
|
@ -35,6 +35,7 @@ import { playground } from "./playground";
|
|||
import { render } from "preact";
|
||||
import { settings } from "./globalSettings";
|
||||
import i18next from "i18next";
|
||||
import { prePageChecks } from "./pageUtils";
|
||||
|
||||
async function onLoad(): Promise<void> {
|
||||
document.documentElement.dir = settings.pageDirection;
|
||||
|
@ -70,6 +71,19 @@ async function onLoad(): Promise<void> {
|
|||
}
|
||||
}
|
||||
}, 5000);
|
||||
|
||||
|
||||
// DO NOT DO THIS
|
||||
// THIS IS BAD
|
||||
// I DO NOT RECOMMEND THIS
|
||||
// WE NEED A BETTER WAY
|
||||
// THIS IS **TRASH**
|
||||
// DO NOT
|
||||
// BAD
|
||||
setInterval(async () => {
|
||||
if (["/set_language", "/set_vault_url", "/unseal", "/login", "/me", "/pw_gen"].includes(getCurrentUrl())) return;
|
||||
await prePageChecks(api, settings);
|
||||
}, 1000)
|
||||
}
|
||||
|
||||
document.addEventListener(
|
||||
|
|
|
@ -5,34 +5,42 @@ import ClipboardJS from "clipboard";
|
|||
import UIkit from "uikit";
|
||||
import i18next from "i18next";
|
||||
|
||||
async function prePageChecksReal(api: API, settings: Settings) {
|
||||
async function prePageChecksReal(api: API, settings: Settings): Promise<boolean> {
|
||||
if (settings.language.length == 0) {
|
||||
console.log("set languge")
|
||||
route("/set_language", true);
|
||||
throw new Error("Language Not Set");
|
||||
return true
|
||||
}
|
||||
|
||||
if (!settings.apiURL) {
|
||||
route("/set_vault_url", true);
|
||||
throw new Error("Vault URL Not Set");
|
||||
if (settings.apiURL.length == 0) {
|
||||
route("/set_vault_url", false);
|
||||
return true
|
||||
}
|
||||
|
||||
const sealStatus = await api.getSealStatus();
|
||||
if (sealStatus.sealed) {
|
||||
route("/unseal", true);
|
||||
throw new Error("Vault Sealed");
|
||||
return true
|
||||
}
|
||||
|
||||
try {
|
||||
await api.lookupSelf();
|
||||
} catch (e) {
|
||||
route("/login", true);
|
||||
throw e;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
// ?????????????????????????????
|
||||
// return trues if checks failed
|
||||
// return false if checks passed
|
||||
// ?????????????????????????????
|
||||
export async function prePageChecks(api: API, settings: Settings): Promise<boolean> {
|
||||
try {
|
||||
await prePageChecksReal(api, settings);
|
||||
if (await prePageChecksReal(api, settings)) {
|
||||
return false;
|
||||
}
|
||||
} catch (e) {
|
||||
console.log("OHNO", e);
|
||||
return false;
|
||||
|
|
|
@ -90,7 +90,7 @@ export const Main = () => (
|
|||
<TOTPNew path="/secrets/totp/new/:baseMount" settings={settings} api={api} />
|
||||
<TOTPNewGenerated path="/secrets/totp/new_generated/:baseMount" settings={settings} api={api} />
|
||||
<TOTPDelete
|
||||
path="/secrets/totp/delete/:version/:baseMount/:item"
|
||||
path="/secrets/totp/delete/:baseMount/:item"
|
||||
settings={settings}
|
||||
api={api}
|
||||
/>
|
||||
|
|
|
@ -24,7 +24,7 @@ export class Settings {
|
|||
|
||||
get apiURL(): string | null {
|
||||
const apiurl = this.storage.getItem("apiURL") || "";
|
||||
return apiurl.length > 0 ? apiurl : null;
|
||||
return apiurl;
|
||||
}
|
||||
set apiURL(value: string) {
|
||||
this.storage.setItem("apiURL", value);
|
||||
|
|
|
@ -17,8 +17,6 @@ type HomeState = {
|
|||
|
||||
export class Home extends Component<DefaultPageProps, HomeState> {
|
||||
async componentDidMount() {
|
||||
if (!(await prePageChecks(this.props.api, this.props.settings))) return;
|
||||
|
||||
let selfTokenInfo: TokenInfo;
|
||||
try {
|
||||
selfTokenInfo = await this.props.api.lookupSelf();
|
||||
|
|
Loading…
Reference in a new issue