Hi <@498057949541826571> , even when i resend code...
# general
a
Hi @rp_st , even when i resend code , then also i am able to use the old code and get success respose , but ideally this should not be the case. Any specific reason why its happening
r
hey @anurag06557 this is expected. Cause for email / sms delivery, the code delivery order is not defined by when you called createcode or resend code. So for better UX, it behaves this way. But once you consume a code, all codes that were sent are removed.
a
is there any thing we could do to avoid this behaviour
@rp_st
r
you can customise how our functions work. You can override the resendCodeAPI on the backend, and then before calling the original implementation, you can get a list of all codes sent using the preAuthSessionId (this value is in the input to the function), and then call revokeCode on each of those codes.
a
ok
i cannot find resendCode here
r
search for resendCodePOST
override that api
a
Hi @rp_st
Copy code
apis: (originalImplementation) => {
        return{
          ...originalImplementation,
          resendCodePOST: async(input)=>{
            // console.log(input)
            const preAuthSessionId = input.preAuthSessionId
            const oldCodes = await listCodesByPreAuthSessionId({preAuthSessionId, tenantId:'public'})
            console.log({oldCodes})
            if(oldCodes?.codes.length > 0){
              for await(const code of oldCodes?.codes){
                console.log(code)
                await revokeCode({codeId:code.codeId, tenantId: 'public'})
              }
            }
            const newCOde = await originalImplementation.resendCodePOST(input)
            console.log({newCOde})
            return newCOde
          }
        };
      },
every time in the newCode response i am getting restartFLowError, why so
is anything wrong i am doing here
r
@porcellus , any idea why this is happening?
p
if you revoke all codes of a device (or preAuthSessionId) the device will be deleted, so you can't resend it
what you should do for this usecase is call resendCode right after listing old codes and only call the revokes after that succeeds
a
ok, trying
succeeded thanks
p
happy to help 🙂
4 Views