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