nalexn / clean-architecture-swiftui

SwiftUI sample app using Clean Architecture. Examples of working with CoreData persistence, networking, dependency injection, unit testing, and more.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Question: Dealing with auth tokens using clean architecture

andreybuksha opened this issue · comments

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)

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.