@@ -57,8 +57,8 @@ It's important to note that when using such a setup, you **don't manually naviga
5757In our navigator, we can conditionally define appropriate screens. For our case, let's say we have 3 screens:
5858
5959- ` SplashScreen ` - This will show a splash or loading screen when we're restoring the token.
60- - ` SignInScreen ` - This is the screen we show if the user isn't signed in already (we couldn't find a token).
61- - ` HomeScreen ` - This is the screen we show if the user is already signed in.
60+ - ` SignIn ` - This is the screen we show if the user isn't signed in already (we couldn't find a token).
61+ - ` Home ` - This is the screen we show if the user is already signed in.
6262
6363So our navigator will look like:
6464
@@ -141,6 +141,12 @@ import * as React from 'react';
141141const AuthContext = React .createContext ();
142142```
143143
144+ In our component, we will:
145+
146+ - Store the token and loading state in ` useReducer `
147+ - Persist it to ` SecureStore ` and read it from there on app launch
148+ - Expose the methods for sign in and sign out to child components using ` AuthContext `
149+
144150So our component will look like this:
145151
146152<samp id =" auth-flow " />
@@ -192,6 +198,7 @@ export default function App({ navigation }) {
192198 }
193199
194200 // After restoring token, we may need to validate it in production apps
201+ // ...
195202
196203 // This will switch to the App screen or Auth screen and this loading
197204 // screen will be unmounted and thrown away.
@@ -224,6 +231,10 @@ export default function App({ navigation }) {
224231 []
225232 );
226233
234+ if (state .isLoading ) {
235+ return < SplashScreen / > ;
236+ }
237+
227238 return (
228239 < AuthContext .Provider value= {authContext}>
229240 < Stack .Navigator >
@@ -268,6 +279,8 @@ function SignInScreen() {
268279}
269280```
270281
282+ You can similarly fill in the other screens according to your requirements.
283+
271284## Removing shared screens when auth state changes
272285
273286Consider the following example:
0 commit comments