I use XState to manage my login state. Not logged in, trying, logged in, log in failed, trying log out, logged out.
The thing I love is the confidence the machine gives me. Unless I’ve buggered up completely, it basically can’t be wrong. That’s incredibly reassuring.
Thanks for XState and all the work you put in to it. It’s an amazing thing.
I've used it for the exact same thing. I had a "userService" machine (embedded in a React UI) that handled all the legwork of an OAuth2 flow and ended with the user in an "authenticated" state with their details as part of the machine context (for use in any other part of the app via a custom hook).
You are absolutely right, it couldn't be wrong. It always just worked exactly the way it was supposed to.
I'm now working on a project that handles logins via a set of disconnected boolean flags flowing through redux and it is a mess.
IsConfirmed IsSent IsSentAndConfirmed IsDraft IsLoading IsInTheEther IsError IsNaN
I want to rewind the clock for a redo on that mega component but I suppose refactoring will have to do. Again, thank you for that great talk!