diff --git a/src/Login.tsx b/src/Login.tsx index 70b7ab8..308a289 100644 --- a/src/Login.tsx +++ b/src/Login.tsx @@ -1,6 +1,7 @@ import { useEffect, useState } from "react"; import { currentUser, login, User } from "./api"; import Header from "./Header"; +import { useLocation, useNavigate } from "react-router"; export interface LoginProps { onLogin: (user: User) => void; @@ -11,6 +12,8 @@ export const Login = ({ onLogin }: LoginProps) => { const [password, setPassword] = useState(""); const [error, setError] = useState(""); const [loading, setLoading] = useState(false); + const navigate = useNavigate(); + const location = useLocation(); async function doLogin() { setLoading(true); @@ -36,11 +39,11 @@ export const Login = ({ onLogin }: LoginProps) => { } useEffect(() => { - const params = new URLSearchParams(window.location.search); - const queryUsername = params.get("username"); - const queryPassword = params.get("password"); + const queryUsername = location.state.username; + const queryPassword = location.state.password; if (queryUsername) setUsername(queryUsername); if (queryPassword) setPassword(queryPassword); + navigate(location.pathname, { replace: true }); }, []); return ( diff --git a/src/SetPassword.tsx b/src/SetPassword.tsx index de64cb5..f62540e 100644 --- a/src/SetPassword.tsx +++ b/src/SetPassword.tsx @@ -55,9 +55,9 @@ export const SetPassword = () => { if (resp.ok) { console.log(resp); - navigate({ - pathname: "/", - search: `?username=${encodeURI(username)}&password=${encodeURI(password)}`, + navigate("/", { + replace: true, + state: { username: username, password: password }, }); }