Improve flow
This commit is contained in:
parent
b51606eb77
commit
d3061d9726
3 changed files with 11 additions and 4 deletions
|
|
@ -26,7 +26,7 @@ export const App = () => {
|
|||
<Route
|
||||
path="/"
|
||||
element={
|
||||
<ProtectedRoute to="/landing">
|
||||
<ProtectedRoute to="/login">
|
||||
<TabloPage />
|
||||
</ProtectedRoute>
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
import { ReactNode, useEffect } from "react";
|
||||
import { useSession } from "../contexts/SessionContext";
|
||||
import { useNavigate } from "react-router-dom";
|
||||
|
||||
interface ProtectedRouteProps {
|
||||
children: ReactNode;
|
||||
to?: string;
|
||||
|
|
@ -9,11 +10,16 @@ interface ProtectedRouteProps {
|
|||
export const ProtectedRoute = ({ children, to }: ProtectedRouteProps) => {
|
||||
const { session } = useSession();
|
||||
const navigate = useNavigate();
|
||||
|
||||
useEffect(() => {
|
||||
let timer = setTimeout(() => {
|
||||
const timer = setTimeout(() => {
|
||||
if (!session) {
|
||||
navigate(to ?? "/landing");
|
||||
const isFirstTimeUser =
|
||||
localStorage.getItem("xtablo-has-seen-landing-page") === null;
|
||||
if (isFirstTimeUser) {
|
||||
navigate("/landing");
|
||||
} else {
|
||||
navigate(to ?? "/login");
|
||||
}
|
||||
}
|
||||
}, 300);
|
||||
return () => clearTimeout(timer);
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@ import logo from "../assets/icon.jpg";
|
|||
import { Header } from "../components/header";
|
||||
|
||||
export const LandingPage = () => {
|
||||
localStorage.setItem("xtablo-has-seen-landing-page", "true");
|
||||
return (
|
||||
<>
|
||||
<Header />
|
||||
|
|
|
|||
Loading…
Reference in a new issue