feat: navigate to home page after login if not explicit

This commit is contained in:
2025-05-29 12:35:48 +02:00
parent e4d83e75a0
commit 56755ac531

View File

@ -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<LoginForm> = 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 (