amplify-js: understanding React SignOut hoc - doesn't work until reload
Now that there’s a SignOut hoc in aws-amplify-react 1.0.x I tried a simple test by inserting it as a component in a fresh create-react-app App.js (that is also wrapped by withAuthenticator)
If I click the “Sign Out” button that it creates nothing happens - the authData and authState are not affected until I manually reload the page in the browser, they they’re cleared.
Am I misunderstanding that the point of this component to fully trigger a signout sequence, including a rerender or redirect once the state is updated? If not why not just build your own call to Auth.signOut() that includes the rerender or redirect?
About this issue
- Original URL
- State: closed
- Created 6 years ago
- Reactions: 7
- Comments: 17 (5 by maintainers)
When using
<AmplifySignOut />, a user is redirected to the login page after signing out. This is the expected UX. However, when usingAuth.signOut()this does not happen. It would be convenient if there was an option when callingsignOutto trigger the same behavior.@powerful23 Thanks, you made my day! Unfortunately I think the “Amplify Team” should have a look at this - either adding your information to their docs, or by changing the
Auth.signOut()method.Proposed change to the
Auth.signOut()method: Add an argument/flag, which allows the user to completely sign out the user when using a single-page application usingwithAuthenticatororAuthenticator. It should be unnecessary for the developer to have to add the extra code as mentioned in the example above.Hi, here is how I handle it (I had to read aws-amplify-react code to understand the behavior)
I use a react context to have a reference on the method to change state of the Authenticator
An redirect works fine.
First time I used amplify it was with react native. I was very surprise with amplify-react behavior. On react native I did not have to make all this stuff.
So the current workaround is to reload your app like this?
@jonasao
Auth.signOut()only clears the tokens stored in cache. In order to change the state back tosignInwhen usingwithAuthenticatororAuthenticator, you need to do something like:@jonasao I agree we need either enhance the doc or we can make the
Authenticatorlisten on theHubevent so that when asignOutevent emitted from the library, it will change the state back tosignIn.Any update on this? I think everyone can agree both the direct API and component should have a similar UX.