From 56755ac5318d9485e31a5c5a966c905750b718ae Mon Sep 17 00:00:00 2001 From: LandaMm Date: Thu, 29 May 2025 12:35:48 +0200 Subject: [PATCH] feat: navigate to home page after login if not explicit --- web/src/pages/Login/index.tsx | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/web/src/pages/Login/index.tsx b/web/src/pages/Login/index.tsx index 5c1c016..0a88ea4 100644 --- a/web/src/pages/Login/index.tsx +++ b/web/src/pages/Login/index.tsx @@ -1,7 +1,7 @@ /* eslint-disable @typescript-eslint/no-explicit-any */ import { Card, CardContent } from "@/components/ui/card"; import { Mail, Lock } from "lucide-react"; -import { Link } from "react-router-dom"; +import { Link, useLocation, useNavigate } from "react-router-dom"; import { Input } from "@/components/ui/input"; import { Button } from "@/components/ui/button"; @@ -33,6 +33,9 @@ export default function LoginPage() { const repo = useAccountRepo(); + const location = useLocation(); + const navigate = useNavigate(); + const updateActiveAccount = useAuth((state) => state.updateActiveAccount); const onSubmit: SubmitHandler = useCallback( @@ -64,7 +67,11 @@ export default function LoginPage() { reset(); oauth.selectSession(response.access); - updateActiveAccount(account); + await updateActiveAccount(account); + + if (!location.state?.from) { + navigate("/"); + } } catch (err: any) { console.log(err); setError( @@ -75,7 +82,7 @@ export default function LoginPage() { setLoading(false); } }, - [oauth, repo, reset, updateActiveAccount] + [repo, reset, oauth, updateActiveAccount, location.state?.from, navigate] ); return (