Skip to content

Commit c3e6864

Browse files
committed
Update auth-flow docs
1 parent 3998967 commit c3e6864

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

versioned_docs/version-5.x/auth-flow.md

+6-2
Original file line numberDiff line numberDiff line change
@@ -44,12 +44,14 @@ This pattern has been in use by other routing libraries such as React Router for
4444

4545
The magic happens when the value of the `isSignedIn` variable changes. Let's say, initially `isSignedIn` is `false`. This means, either `SignIn` or `SignUp` screens are shown. After the user signs in, the value of `isSignedIn` will change to `true`. React Navigation will see that the `SignIn` and `SignUp` screens are no longer defined and so it will remove them. Then it'll show the `Home` screen automatically because that's the first screen defined when `isSignedIn` is `true`.
4646

47-
It's important to note that when using such a setup, you **don't need to manually navigate** to the `Home` screen by calling `navigation.navigate('Home')` or any other method. **React Navigation will automatically navigate to the correct screen** when `isSigned` in changes - `Home` screen when `isSignedIn` becomes `true`, and to `SignIn` screen when `isSignedIn` becomes `false`. You'll get an error if you attempt to navigate manually.
48-
4947
The example shows stack navigator, but you can use the same approach with any navigator.
5048

5149
By conditionally defining different screens based on a variable, we can implement auth flow in a simple way that doesn't require additional logic to make sure that the correct screen is shown.
5250

51+
## Don't manually navigate when conditionally rendering screens
52+
53+
It's important to note that when using such a setup, you **don't manually navigate** to the `Home` screen by calling `navigation.navigate('Home')` or any other method. **React Navigation will automatically navigate to the correct screen** when `isSigned` in changes - `Home` screen when `isSignedIn` becomes `true`, and to `SignIn` screen when `isSignedIn` becomes `false`. You'll get an error if you attempt to navigate manually.
54+
5355
## Define our screens
5456

5557
In our navigator, we can conditionally define appropriate screens. For our case, let's say we have 3 screens:
@@ -112,6 +114,8 @@ state.userToken == null ? (
112114
);
113115
```
114116

117+
> If you have both your login-related screens and rest of the screens in Stack navigators, we recommend to use a single Stack navigator and place the conditional inside instead of using 2 different navigators. This makes it possible to have a proper transition animation during login/logout.
118+
115119
## Implement the logic for restoring the token
116120

117121
> Note: The following is just an example of how you might implement the logic for authentication in your app. You don't need to follow it as is.

versioned_docs/version-6.x/auth-flow.md

+6-2
Original file line numberDiff line numberDiff line change
@@ -44,12 +44,14 @@ This pattern has been in use by other routing libraries such as React Router for
4444

4545
The magic happens when the value of the `isSignedIn` variable changes. Let's say, initially `isSignedIn` is `false`. This means, either `SignIn` or `SignUp` screens are shown. After the user signs in, the value of `isSignedIn` will change to `true`. React Navigation will see that the `SignIn` and `SignUp` screens are no longer defined and so it will remove them. Then it'll show the `Home` screen automatically because that's the first screen defined when `isSignedIn` is `true`.
4646

47-
It's important to note that when using such a setup, you **don't need to manually navigate** to the `Home` screen by calling `navigation.navigate('Home')` or any other method. **React Navigation will automatically navigate to the correct screen** when `isSigned` in changes - `Home` screen when `isSignedIn` becomes `true`, and to `SignIn` screen when `isSignedIn` becomes `false`. You'll get an error if you attempt to navigate manually.
48-
4947
The example shows stack navigator, but you can use the same approach with any navigator.
5048

5149
By conditionally defining different screens based on a variable, we can implement auth flow in a simple way that doesn't require additional logic to make sure that the correct screen is shown.
5250

51+
## Don't manually navigate when conditionally rendering screens
52+
53+
It's important to note that when using such a setup, you **don't manually navigate** to the `Home` screen by calling `navigation.navigate('Home')` or any other method. **React Navigation will automatically navigate to the correct screen** when `isSigned` in changes - `Home` screen when `isSignedIn` becomes `true`, and to `SignIn` screen when `isSignedIn` becomes `false`. You'll get an error if you attempt to navigate manually.
54+
5355
## Define our screens
5456

5557
In our navigator, we can conditionally define appropriate screens. For our case, let's say we have 3 screens:
@@ -112,6 +114,8 @@ state.userToken == null ? (
112114
);
113115
```
114116

117+
> If you have both your login-related screens and rest of the screens in Stack navigators, we recommend to use a single Stack navigator and place the conditional inside instead of using 2 different navigators. This makes it possible to have a proper transition animation during login/logout.
118+
115119
## Implement the logic for restoring the token
116120

117121
> Note: The following is just an example of how you might implement the logic for authentication in your app. You don't need to follow it as is.

0 commit comments

Comments
 (0)