#[SOLVED] 2FA

51 messages · Page 1 of 1 (latest)

midnight frigate
#

I am trying to generate a QRCode for my 2FA, it generates the qrcode, I can add it to my authenticator app, but then when I enter the passcode to verify it says AppwriteException: Invalid token passed in the request.

This is my code if anyone could help?

// ============================== ADD AUTHENTICATOR
export async function startAddAuthenticator() {
  try {

    const result1 = await account.createMfaAuthenticator(
      AuthenticatorType.Totp // type
    );

    if (!result1) return null;

    const qr = avatars.getQR(result1.uri, 800, 0, false);

    return { qr, secret: result1.secret };
  } catch (error) {
    console.log(error);
  }
}

// ============================== VERIFY AUTHENTICATOR
export async function verifyAuthenticator(code: string) {

  try {
    const result = await account.updateMfaAuthenticator(
      AuthenticatorType.Totp, // type
      code // code
    );

    if (!result) return null;

    return result;
  } catch (error) {
    console.log(error);
  }
}
midnight frigate
#

2FA

midnight frigate
#

Any help would be appreciated

rugged apex
#

Are you sure the code you're passing through is correct?

midnight frigate
#

yeah, the qrcode is generated, I then input the code from the authenticator app and get that error every time. Do I need to enable mfa first? because i've tried that and it still doesnt work

#

and the payload is something like

otp: "461899"

midnight frigate
#

anyone able to give me an idea?

I've followed the guide, I get the qr code, i pass it the href and it displays. I can add it to my authenticator app, get a code but then everytime I enter that code into my app to verify the mfa and enable it for that account it gives the error above

rugged radish
#

This will be fixed in the future version I think, where appwrite will automatically turn it on for you

#

However, your code just seems to be incorrect

midnight frigate
rugged radish
#

So your 2fa is getting a code correctly, right?

midnight frigate
#

yeah

rugged radish
#

Where is your code coming from that's going to verifyAuthenticator?

midnight frigate
#

from the users input

rugged radish
#

hmm

midnight frigate
#

does it have to be passed a certain way with like spacing or dashes separating each three. IDK because whatever code the authenticator gives me is the one I'm adding in and it just doesn't like it

rugged radish
#

nope, just the code

midnight frigate
#

from what I can see, the difference is your running this on the page itself and Im calling it from a different file

rugged radish
#

it's not a page, it's a component

#

but yes, mostly

midnight frigate
#

yeah, that's the only difference

rugged radish
#

might have to wait for the big guns to help (steven)

#

you could try using a normal input field instead

#

maybe your current input is wrongly putting in the numbers

#

but i wouldn't know what else

midnight frigate
#

Im using shadcn's input like yours

#

ill just wait

#

ty though

proud niche
#

what's your project id and user id?

midnight frigate
midnight frigate
proud niche
#

like 250 in 1 second 👀

midnight frigate
#

wtaf, how would I fix this?

rugged radish
#

that's impressive

midnight frigate
#

okay so it works for other users, just not that user

proud niche
#

there's 7.3k authenticators associated with the user!

#

all on the 26th

midnight frigate
#

I have no idea, I literally tried maybe like 10 times, could have been that my code just kept regenerating authenticators?

proud niche
midnight frigate
#

I believe so yeah, it is sorted now, kind of. Just need to work out my AuthContext, but I can add the authenticator now. Might just need to re-add that user and go through the steps again

proud niche
midnight frigate
#

No worries, I will do that. I will change this to sorted. ty

#

SORTED: 2FA