Get user data in ngOnInit

Outside of that then block, you have no idea when token is valid.

The reason I want async/await to go away is that they obscure the flow of code, which is the fundamental problem here. You are writing in an imperative style: do this, do that, then do this. async and await exist in order to make things look imperative, which IMHO has the bad side-effect of convincing people that they can actually make things imperative. They can’t.

You are saying “do I have a token? if not, get a token. now go fire off an http request”. Web apps don’t work like that: they are reactive by necessity, because you the programmer does not control the flow of execution: it’s dependent on external factors like networks and storage latency.

You might want to look at the latter half of this thread, which covers very similar territory to your use case: getting a token from storage and using it in HTTP requests. One strategy I often use is to break each step up into a separate function, giving each of them explicit parameter and return types. This allows the compiler to tell me when I’m structuring things in an impossible way. Never use external state (like this.user, this.token, &c) amongst asynchronous code: it can be very difficult for either humans or static code analysis tools to spot situations where you introduce race conditions like the one you have here with the token.

The more strictly I follow the rules of functional programming when doing asynchronous JavaScript, the happier I find myself.