feat(login): enhance routing by preserving 'from' path in login redirects

This commit is contained in:
2026-03-12 01:14:16 +08:00
parent 2479653bab
commit 4e16e933f2
2 changed files with 5 additions and 3 deletions

View File

@@ -10,6 +10,7 @@ function LoginForm() {
const router = useRouter();
const searchParams = useSearchParams();
const justSetup = searchParams.get("setup") === "1";
const fromPath = searchParams.get("from");
const [username, setUsername] = useState("");
const [password, setPassword] = useState("");
const [error, setError] = useState("");
@@ -29,7 +30,7 @@ function LoginForm() {
if (res.error) {
setError(res.error.message ?? "登录失败,请检查用户名和密码");
} else {
router.push("/dashboard");
router.push(fromPath ?? "/dashboard");
router.refresh();
}
} catch {
@@ -47,7 +48,7 @@ function LoginForm() {
if (res?.error) {
setError(res.error.message ?? "Passkey 登录失败");
} else {
router.push("/dashboard");
router.push(fromPath ?? "/dashboard");
router.refresh();
}
} catch {