feat: automatically switch to index and fill in newly given creds
This commit is contained in:
parent
045c26d258
commit
b386ee365f
@ -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 (
|
||||
|
@ -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 },
|
||||
});
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user