React-navigation: Deep linking with authentication : <p>I am building a mobile app with react-native and the react-navigation library for managing the navigation in my app. Right now, my app looks something like that:</p>

<pre><code>App [SwitchNavigator]
    Splash [Screen]
    Auth [Screen]
    MainApp [StackNavigator]
        Home [Screen]            (/home)
        Profile [Screen]         (/profile)
        Notifications [Screen]   (/notifications)
</code></pre>

<p>I have integrated Deep Linking with the patterns above for the screens <code>Home</code>, <code>Profile</code> and <code>Notifications</code>, and it works as expected. The issue I am facing is how to manage my user's authentication when using a deep link. Right now whenever I open a deep link (<code>myapp://profile</code> for instance) the app takes me on the screen whether or not I am authenticated. What I would want it to do is to check before in <code>AsyncStorage</code> if there is a <code>userToken</code> and if there isn't or it is not valid anymore then just redirect on the <code>Auth</code> screen.</p>

<p>I set up the authentication flow in almost exactly the same way as described <a href="https://reactnavigation.org/docs/en/auth-flow.html" rel="noreferrer">here</a>. So when my application starts the <code>Splash</code> screen checks in the user's phone if there is a valid token and sends him either on the <code>Auth</code> screen or <code>Home</code> screen.</p>

<p>The only solution I have come up with for now is to direct every deep link to <code>Splash</code>, authentify my user, and then parse the link to navigate to the good screen.
So for example when a user opens <code>myapp://profile</code>, I open the app on <code>Splash</code>, validate the token, then parse the url (<code>/profile</code>), and finally redirect either to <code>Auth</code> or <code>Profile</code>.</p>

<p>Is that the good way to do so, or does react-navigation provide a better way to do this ? The <a href="https://reactnavigation.org/docs/en/deep-linking.html" rel="noreferrer">Deep linking</a> page on their website is a little light.</p>

<p>Thanks for the help !</p>
