hooks#useAuth JavaScript Examples
The following examples show how to use
hooks#useAuth.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: App.jsx From react-chatengine-demo with MIT License | 6 votes |
App = () => {
const history = useHistory();
const { authUser } = useAuth();
const authResolved = useResolved(authUser);
// If the user is logged in it will prevent the
// user from seeing the login/signup screens
// by always redirecting to chat on auth change.
useEffect(() => {
if (authResolved) {
history.push(!!authUser ? '/' : '/login');
}
}, [authResolved, authUser, history]);
return authResolved ? (
<ChatProvider authUser={authUser}>
<div className="app">
<Switch>
<Route path="/" exact component={Chat} />
<Route path="/login" component={Login} />
<Route path="/signup" component={Signup} />
</Switch>
</div>
</ChatProvider>
) : (
<>Loading...</>
);
}