Open onmyway133 opened 3 years ago
Using this pattern how would authService manipulate the userState value? Would the App ViewModel be listening to the authService? Thanks.
@SApolinario ja, one way is to let ViewModel listens to AuthService for changes
For many apps that require user authentication, a common practice is to define a shared
UserManager
with an optionalUser
. This is convenient but it requires us to constantly unwrap and check thatuser
A more safer approach is to leverage Swift type system and separate the need based on authenticated and unauthenticated usage. For example, for an unauthorized users, we show the login screen. For authorized users but haven't completed profile customization yet, we show onboarding. And finally, show the main screen.
Define UserState
Depend on the app, we can define a
UserState
. Here, after the user has logged in with Apple ID, we need to onboard them with few questions for profile settings before taking them to the main flow.Entry AppView
Then in our entry
AppView
, we can show different parts of the app depending on thisuserState
Onboard flow
We only show OnboardView given that the user has authorized, this requirement needs the
user
to be nonnil. Since our UserState is predictable we can just pass theuser
to the Onboard flowNote here how we use underscore
_
to access the containerStateObject
to initializeRead more