Skip to content

Commit

Permalink
feat: Implement cookie to prefill username and password form
Browse files Browse the repository at this point in the history
  • Loading branch information
PintoGideon committed Jun 18, 2024
1 parent 44071b0 commit 096b613
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions src/components/PluginInstall/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@ import WrapperConnect from "../Wrapper";
import { Alert } from "antd";
import { SpinContainer } from "../Common";
import { useNavigate } from "react-router";
import { useCookies, Cookies } from "react-cookie";

const PluginInstall = () => {
const [_cookie, setCookie] = useCookies();
const navigate = useNavigate();
const [showHelperText, setShowHelperText] = React.useState(false);
const [username, setUsername] = React.useState("");
Expand Down Expand Up @@ -62,11 +64,34 @@ const PluginInstall = () => {
mutationFn: async () => await handleSave(),
});

React.useEffect(() => {
const cookies = new Cookies();

if (cookies.get("admin_username")) {
setUsername(cookies.get("admin_username"));
}

if (cookies.get("admin_password")) {
setPassword(cookies.get("admin_password"));
}
}, []);

React.useEffect(() => {
if (isSuccess) {
if (data) {
const id = data.collection.items[0].data[0].value;
if (typeof id === "number" && !Number.isNaN(id)) {
if (isRememberMeChecked) {
const oneDayToSeconds = 24 * 60 * 60;
setCookie("admin_username", username, {
path: "/",
maxAge: oneDayToSeconds,
});
setCookie("admin_password", password, {
path: "/",
maxAge: oneDayToSeconds,
});
}
navigate(`/plugin/${id}`);
}
}
Expand Down

0 comments on commit 096b613

Please sign in to comment.