mirror of
https://github.com/cheveguerra/whaticket-community.git
synced 2026-04-19 20:29:17 +00:00
improvement: keep user data on login fails
This commit is contained in:
@@ -7,19 +7,30 @@ import BackdropLoading from "../components/BackdropLoading";
|
||||
const RouteWrapper = ({ component: Component, isPrivate = false, ...rest }) => {
|
||||
const { isAuth, loading } = useContext(AuthContext);
|
||||
|
||||
if (loading) return <BackdropLoading />;
|
||||
|
||||
if (!isAuth && isPrivate) {
|
||||
return (
|
||||
<Redirect to={{ pathname: "/login", state: { from: rest.location } }} />
|
||||
<>
|
||||
{loading && <BackdropLoading />}
|
||||
<Redirect to={{ pathname: "/login", state: { from: rest.location } }} />
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
if (isAuth && !isPrivate) {
|
||||
return <Redirect to={{ pathname: "/", state: { from: rest.location } }} />;
|
||||
return (
|
||||
<>
|
||||
{loading && <BackdropLoading />}
|
||||
<Redirect to={{ pathname: "/", state: { from: rest.location } }} />;
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
return <Route {...rest} component={Component} />;
|
||||
return (
|
||||
<>
|
||||
{loading && <BackdropLoading />}
|
||||
<Route {...rest} component={Component} />
|
||||
</>
|
||||
);
|
||||
};
|
||||
|
||||
export default RouteWrapper;
|
||||
|
||||
Reference in New Issue
Block a user