Creating a login/logout flow with RxJs in Angular

Viewed 30

I am currently in the very early stages of learning to utilize RxJs, and while i do think i am starting to get the basics, there are still things i do not entirely understand.

What i am currently trying to solve is the login flow in my web app.

I have connected a couple of observables to certain events, such as changing the value of a drop down, that loads the correct data, and shows it in my view.

But there are a couple of things that bug me that i cannot entirely realize how to do/why it does not work as expected.

  • I have a header menu that should appear when i am logged in, which it currently does correctly. However, when i log out as a user, the menu does not disappear. I imagine i should use some kind of subject to fire an event whenever i log in or log out, that my components can subscribe to, to figure out if they should get shown or not. I am not sure if this is the right way to create such a system though.
  • I also currently have the problem that my observables do not load correctly if i as a user refresh the page. It seems the chain of observables only correctly fire if i actually start with my login, where i fire the login event that the rest of the observables is subscribed to.

I sadly cannot provide much code at the moment, but as i am mostly looking for the thought process behind how to go about creating such a login flow through Reactive programming, i hope it does not matter too much. Hopefully my question should also make some kind of sense (despite it being a bit broad).

0 Answers
Related