DEV Community

[Comment from a deleted post]
Collapse
 
chiangs profile image
Stephen Chiang

You shouldn't have a hook inside a conditional. Try upgrading to Scripts 3.0 and the linter should mention that.

You can also refer to the rule of 3

Instead, have the hook run on initial load every time using the empty dependency array argument and inside that hook run the conditional logic.

And instead of returning navigator.. Just return an <authorized> or <unauthorized> component that wraps the relevant routes. In your case the unauthorized component would just wrap the sign in page... If you are using a 3rd party sign in page then you can just return the route via their specifications.

Here's an example

From