nalexn / clean-architecture-swiftui

SwiftUI sample app using Clean Architecture. Examples of working with CoreData persistence, networking, dependency injection, unit testing, and more.
MIT License
5.74k stars 698 forks source link

Question: Dealing with auth tokens using clean architecture #22

Closed andreybuksha closed 4 years ago

andreybuksha commented 4 years ago

How should I set auth token? After I authenticate I need to pass auth token in headers for every request. In your article you briefly mentioned that tokens would be stored in AppState. But how can I access token stored in state on Repository level (since we set headers over there)

nalexn commented 4 years ago

You can simply inject Store<AppState> as an init parameter at the lowest networking level (URLSession) or at the level of Repositories. AppState is created before all the rest of the infrastructure, so you can inject it in any system module that needs it.