Good evening all,
today I wanted to add MFA using TOTP but failed on activating it as the last step always returns:
https://myappwriteinstacne.example.com/v1/account/mfa/authenticators/totp 401 (Unauthorized)
The user is correctly signed in and I can recieve account informations using account.get().
My code looks like this:
import { useState, useEffect } from "react";
import { account, avatars } from "./AppwriteConfig";
function Enable2fa() {
const [user, setUser] = useState<any>("");
const [qrCodeUrl, setQrCodeUrl] = useState<string>("");
const [totpSecret, setTotpSecret] = useState<string>("");
const [totpCode, setTOTPCode] = useState<string>("");
useEffect(() => {
const validateSession = async () => {
try {
const getaccount = await account.get();
setUser(getaccount);
} catch {
window.location.replace("/");
return;
}
};
const create2faTotp = async () => {
try {
const { secret, uri } = await (account as any).createMfaAuthenticator(
"totp" // type
);
const result = avatars.getQR(
uri, // url
300, // size
0, // margin
false // download
);
setQrCodeUrl(result);
setTotpSecret(secret);
} catch (error) {
console.log(error);
}
};
validateSession();
create2faTotp();
}, []);
const handleActivation = async () => {
try {
await (account as any).updateMfaAuthenticator(
"totp", // type
totpCode // otp
);
//await account.updateMFA(true);
} catch {
setMessageType("error");
setMessage(
"Failed to enable 2FA. Please verify you're logged in correctly, reload the webpage/app, or get in touch with the application owner."
);
}
};
Does anyone have an Idea on what im doing wrong here?
Many thanks and best regards Finn
Recommended threads
- [SOLVED] Server Error
am trying register a user in my nextjs app with signUpWithEmail but am getiing error ` code: 500, type: 'general_unknown', response: { message: 'Serve...
- TLS cert ACME challenge fails for custom...
Hi All, Probably some traefik/domain issue, but I cannot figure out the problem for days, and any help would be much appreciated. I have 2 domains, let's say ...
- IP is allowed allow authentication witve...
```Error during authentication: AppwriteException: Direct IP access is not allowed in Vercel's Edge environment (hostname: x.x.x.x) at (node_modules/node-a...