Resolved: VIPER architecture and proper place to save access token

In this post, we will see how to resolve VIPER architecture and proper place to save access token


So, lets say that this is a general definition in VIPER architecture:
The main parts of VIPER are:

View: displays what it is told to by the Presenter and relays user input back to the Presenter. Interactor: contains the business logic as specified by a use case. Presenter: contains view logic for preparing content for display (as received from the Interactor) and for reacting to user inputs (by requesting new data from the Interactor). Entity: contains basic model objects used by the Interactor. Routing: contains navigation logic for describing which screens are shown in which order.

Now in my interactor, I do a login network request, and I get the response that has access token (that I later save in keychain using my KeyChainManager).
Now, were would be a good and a proper place to save the token? Immediately in the interactor, or to pass it somewhere further maybe, eg. presenter… ?

Best Answer:

This is a service so that’s what the interactor is for. You should have a service for doing the request and a service for storing or retrieving the token, and only an interactor should be allowed to speak to them or even know of them.
That is, in fact, the whole point of the interactor — it’s so that the presenter does not know anything about this. No one else should know anything about what’s going on. A presenter should know nothing about the token — that it exists or where it is stored. That’s all just behind-the-scenes implementation.

If you have better answer, please add a comment about this, thank you!