fixing mfauth

This commit is contained in:
balzack 2024-09-11 18:35:56 -07:00
parent cda2f377d7
commit 545d9c7993
7 changed files with 23 additions and 14 deletions

View File

@ -130,8 +130,12 @@ export function Settings({ showLogout }: { showLogout: boolean }) {
if (!addingMfa) {
setAddingMfa(true);
try {
await actions.enableMFA();
mfaOpen();
if (checked) {
await actions.enableMFA();
mfaOpen();
} else {
await actions.disableMFA();
}
} catch (err) {
console.log(err)
showError()
@ -143,9 +147,13 @@ export function Settings({ showLogout }: { showLogout: boolean }) {
const confirmMfa = async () => {
if (!savingMfa) {
setSavingMfa(true);
mfaClose();
try {
await actions.confirmMFA();
mfaClose();
} catch (err) {
console.log(err);
showError();
}
setSavingMfa(false);
}
}
@ -351,6 +359,7 @@ export function Settings({ showLogout }: { showLogout: boolean }) {
</div>
<Text className={classes.entryLabel}>{state.strings.mfaTitle}</Text>
<Switch className={classes.entryControl}
checked={state.config.mfaEnabled}
onChange={(ev) => setMfa(ev.currentTarget.checked)}
/>
</div>

View File

@ -159,9 +159,9 @@ export function useSettings() {
const { settings } = getSession()
await settings.disableMFA()
},
confirmMFA: async (code: string) => {
confirmMFA: async () => {
const { settings } = getSession()
await settings.confirmMFA(code)
await settings.confirmMFA(state.code)
},
setCode: (code: string) => {
updateState({ code });

View File

@ -160,7 +160,7 @@ export type ConfigEntity = {
sealable: boolean,
seal: SealEntity,
enableIce: boolean,
multiFactorAuth: boolean,
mfaEnabled: boolean,
webPushKey: string,
}
@ -175,7 +175,7 @@ export const defaultConfigEntity = {
seal: { passwordSalt: '', privateKeyIv: '', privateKeyEncrypted: '', publicKey: '' },
sealable: false,
enableIce: false,
multiFactorAuth: false,
mfaEnabled: false,
webPushKey: '',
};

View File

@ -1,7 +1,7 @@
import { checkResponse, fetchWithTimeout } from './fetchUtil';
export async function removeAccountMFAuth(node: string, secure: boolean, token: string) {
const endpoint = `http${secure ? 's' : ''}://${node}/account/mfauth=${token}`;
const endpoint = `http${secure ? 's' : ''}://${node}/account/mfauth?agent=${token}`;
const { status } = await fetchWithTimeout(endpoint, { method: 'DELETE' })
checkResponse(status);
}

View File

@ -1,7 +1,7 @@
import { checkResponse, fetchWithTimeout } from './fetchUtil';
export async function setAccountMFAuth(node: string, secure: boolean, token: string, code: string) {
const endpoint = `http${secure ? 's' : ''}://${node}/account/agent=${token}&code=${code}`;
const endpoint = `http${secure ? 's' : ''}://${node}/account/mfauth?agent=${token}&code=${code}`;
const { status } = await fetchWithTimeout(endpoint, { method: 'PUT' })
checkResponse(status);
}

View File

@ -95,11 +95,11 @@ export class SettingsModule implements Settings {
}
public getConfig() {
const { storageUsed, storageAvailable, forwardingAddress, searchable, allowUnsealed, pushEnabled, sealable, seal, enableIce, multiFactorAuth, webPushKey } = this.config;
const { storageUsed, storageAvailable, forwardingAddress, searchable, allowUnsealed, pushEnabled, sealable, seal, enableIce, mfaEnabled, webPushKey } = this.config;
const { passwordSalt, privateKeyIv, privateKeyEncrypted, publicKey } = seal || {};
const sealSet = Boolean(passwordSalt && privateKeyIv && privateKeyEncrypted && publicKey);
const sealUnlocked = Boolean(sealSet && this.sealKey?.privateKey && this.sealKey?.publicKey == publicKey)
return { storageUsed, storageAvailable, forwardingAddress, searchable, allowUnsealed, pushEnabled, sealable, sealSet, sealUnlocked, enableIce, multiFactorAuth, webPushKey };
return { storageUsed, storageAvailable, forwardingAddress, searchable, allowUnsealed, pushEnabled, sealable, sealSet, sealUnlocked, enableIce, mfaEnabled, webPushKey };
}
public addConfigListener(ev: (config: Config) => void): void {

View File

@ -155,7 +155,7 @@ export type Config = {
sealSet: boolean,
sealUnlocked: boolean,
enableIce: boolean,
multiFactorAuth: boolean,
mfaEnabled: boolean,
webPushKey: string,
}