Improve flow

This commit is contained in:
Arthur Belleville 2025-04-01 18:33:57 +02:00
parent b51606eb77
commit d3061d9726
No known key found for this signature in database
3 changed files with 11 additions and 4 deletions

View file

@ -26,7 +26,7 @@ export const App = () => {
<Route
path="/"
element={
<ProtectedRoute to="/landing">
<ProtectedRoute to="/login">
<TabloPage />
</ProtectedRoute>
}

View file

@ -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);

View file

@ -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 />