Implement 2FA setup and disabling

This commit is contained in:
Johannes Zellner
2025-01-16 17:27:12 +01:00
parent 441b72158d
commit 3955fbdc64
2 changed files with 104 additions and 2 deletions
+33
View File
@@ -124,6 +124,39 @@ function create(origin, accessToken) {
return null;
},
async setTwoFASecret() {
let error, result;
try {
result = await fetcher.post(`${origin}/api/v1/profile/twofactorauthentication_secret`, {}, { access_token: accessToken });
} catch (e) {
error = e;
}
if (error || result.status !== 200) return [error || result];
return [null, result.body];
},
async enableTwoFA(totpToken) {
let error, result;
try {
result = await fetcher.post(`${origin}/api/v1/profile/twofactorauthentication_enable`, { totpToken }, { access_token: accessToken });
} catch (e) {
error = e;
}
if (error || result.status !== 204) return [error || result];
return [null];
},
async disableTwoFA(password) {
let error, result;
try {
result = await fetcher.post(`${origin}/api/v1/profile/twofactorauthentication_disable`, { password }, { access_token: accessToken });
} catch (e) {
error = e;
}
if (error || result.status !== 204) return [error || result];
return [null];
},
};
}