When a user with a token navigates to /:subdomain/login or /:subdomain/otp, they are redirected to /${subdomain}. The redirect uses replace to avoid adding a history entry.
This commit is contained in:
22
src/components/publicRoute/PublicRoute.tsx
Normal file
22
src/components/publicRoute/PublicRoute.tsx
Normal file
@@ -0,0 +1,22 @@
|
||||
import { Loader } from "components/Loader/Loader";
|
||||
import { Navigate, useParams } from "react-router-dom";
|
||||
import { useAppSelector } from "redux/hooks";
|
||||
|
||||
export const PublicRoute = ({
|
||||
children,
|
||||
}: {
|
||||
children: JSX.Element;
|
||||
}) => {
|
||||
const { token, loading } = useAppSelector((state) => state.auth);
|
||||
const { subdomain } = useParams();
|
||||
|
||||
if (loading) {
|
||||
return <Loader />;
|
||||
}
|
||||
|
||||
if (token) {
|
||||
return <Navigate to={`/${subdomain}`} replace />;
|
||||
}
|
||||
|
||||
return children;
|
||||
};
|
||||
Reference in New Issue
Block a user