aws-samples / amazon-cognito-passwordless-auth

Passwordless authentication with Amazon Cognito: FIDO2 (WebAuthn, support for Passkeys), Magic Link, SMS OTP Step Up
Apache License 2.0
367 stars 63 forks source link

Resetting state #171

Closed juanf9224 closed 4 months ago

juanf9224 commented 4 months ago

Hi,

I created multiple state components for some of the signingInStatus states, I have an issue when trying to go back from let's say, EXPIRED state to sign in view, since the sign in page has the conditional render for the expired state if I go back to it it just renders the expired link state component again because the signingInStatus is still on the EXPIRED state, I have to do a reload to reset state, is there any other way to achieve this?

ottokruse commented 4 months ago

Hi!

Can you share a bit more info on what exactly goes wrong?

Do you use the usePasswordless hook or also the prefab components?

Is the sign-in link still in the URL at that point? If you know you'll not need it (because it is expired) you may want to clear it.

ottokruse commented 4 months ago

For conditionally rendering the right UI use the signInStatus field btw not the signingInStatus field.

Just looking at the field signInStatus should be enough to figure out whether or not to show the right sign in page (was made for that purpose). Since being signed in (=have valid JWTs), and signing in, can exist in parallel (eg in case of step up auth), these statuses were separated into two different fields (they are related but not the same).

juanf9224 commented 4 months ago

Hey @ottokruse , sorry for not getting back on this,

the components would be something like this: component A has => component B, C ,D, E A ---- By default render B ---- if Expired render C ---- if Sent render D ---- if Invalid render E ----------- if go back to sign in clicked, render A with cleared status so sign in form is shown

juanf9224 commented 4 months ago

@ottokruse I ended up using a state to handle this, was hoping to be able to use the same hook but this way is not complex so I guess not really important to have such functionality.