feat: automatically switch to index and fill in newly given creds

This commit is contained in:
julius 2025-03-11 08:25:33 +01:00
parent 045c26d258
commit b386ee365f
Signed by: julius
GPG Key ID: C80A63E6A5FD7092
2 changed files with 9 additions and 6 deletions

View File

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

View File

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