mirror of
https://github.com/uqbar-dao/nectar.git
synced 2024-12-23 00:21:38 +03:00
Merge pull request #577 from kinode-dao/dr/improve-login-redirect
Improve login redirect
This commit is contained in:
commit
d577abed9c
@ -21,7 +21,6 @@ function App() {
|
|||||||
const [reset, setReset] = useState<boolean>(false);
|
const [reset, setReset] = useState<boolean>(false);
|
||||||
const [direct, setDirect] = useState<boolean>(false);
|
const [direct, setDirect] = useState<boolean>(false);
|
||||||
const [knsName, setKnsName] = useState<string>('');
|
const [knsName, setKnsName] = useState<string>('');
|
||||||
const [appSizeOnLoad, setAppSizeOnLoad] = useState<number>(0);
|
|
||||||
const [networkingKey, setNetworkingKey] = useState<string>('');
|
const [networkingKey, setNetworkingKey] = useState<string>('');
|
||||||
const [ipAddress, setIpAddress] = useState<number>(0);
|
const [ipAddress, setIpAddress] = useState<number>(0);
|
||||||
const [ws_port, setWsPort] = useState<number>(0);
|
const [ws_port, setWsPort] = useState<number>(0);
|
||||||
@ -36,10 +35,6 @@ function App() {
|
|||||||
const openConnect = () => setConnectOpen(true)
|
const openConnect = () => setConnectOpen(true)
|
||||||
const closeConnect = () => setConnectOpen(false)
|
const closeConnect = () => setConnectOpen(false)
|
||||||
|
|
||||||
useEffect(() => setAppSizeOnLoad(
|
|
||||||
(window.performance.getEntriesByType('navigation') as any)[0].transferSize
|
|
||||||
), []);
|
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
(async () => {
|
(async () => {
|
||||||
try {
|
try {
|
||||||
@ -84,7 +79,7 @@ function App() {
|
|||||||
// todo, most of these can be removed...
|
// todo, most of these can be removed...
|
||||||
const props = {
|
const props = {
|
||||||
direct, setDirect,
|
direct, setDirect,
|
||||||
key, appSizeOnLoad,
|
key,
|
||||||
keyFileName, setKeyFileName,
|
keyFileName, setKeyFileName,
|
||||||
reset, setReset,
|
reset, setReset,
|
||||||
pw, setPw,
|
pw, setPw,
|
||||||
|
@ -21,7 +21,6 @@ export interface PageProps {
|
|||||||
setReset: React.Dispatch<React.SetStateAction<boolean>>,
|
setReset: React.Dispatch<React.SetStateAction<boolean>>,
|
||||||
pw: string,
|
pw: string,
|
||||||
setPw: React.Dispatch<React.SetStateAction<string>>,
|
setPw: React.Dispatch<React.SetStateAction<string>>,
|
||||||
appSizeOnLoad: number,
|
|
||||||
nodeChainId: string,
|
nodeChainId: string,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -7,13 +7,13 @@ import {
|
|||||||
import { PageProps } from "../lib/types";
|
import { PageProps } from "../lib/types";
|
||||||
import Loader from "../components/Loader";
|
import Loader from "../components/Loader";
|
||||||
import { sha256, toBytes } from "viem";
|
import { sha256, toBytes } from "viem";
|
||||||
|
import { redirectToHomepage } from "../utils/redirect-to-homepage";
|
||||||
|
|
||||||
interface ImportKeyfileProps extends PageProps { }
|
interface ImportKeyfileProps extends PageProps { }
|
||||||
|
|
||||||
function ImportKeyfile({
|
function ImportKeyfile({
|
||||||
pw,
|
pw,
|
||||||
setPw,
|
setPw,
|
||||||
appSizeOnLoad,
|
|
||||||
}: ImportKeyfileProps) {
|
}: ImportKeyfileProps) {
|
||||||
|
|
||||||
const [localKey, setLocalKey] = useState<Uint8Array | null>(null);
|
const [localKey, setLocalKey] = useState<Uint8Array | null>(null);
|
||||||
@ -70,24 +70,15 @@ function ImportKeyfile({
|
|||||||
if (result.status > 399) {
|
if (result.status > 399) {
|
||||||
throw new Error("Incorrect password");
|
throw new Error("Incorrect password");
|
||||||
}
|
}
|
||||||
|
redirectToHomepage();
|
||||||
|
|
||||||
const interval = setInterval(async () => {
|
|
||||||
const res = await fetch("/", { credentials: 'include' });
|
|
||||||
if (
|
|
||||||
res.status < 300 &&
|
|
||||||
Number(res.headers.get("content-length")) !== appSizeOnLoad
|
|
||||||
) {
|
|
||||||
clearInterval(interval);
|
|
||||||
window.location.replace("/");
|
|
||||||
}
|
|
||||||
}, 2000);
|
|
||||||
}
|
}
|
||||||
} catch {
|
} catch {
|
||||||
window.alert("An error occurred, please try again.");
|
window.alert("An error occurred, please try again.");
|
||||||
setLoading(false);
|
setLoading(false);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
[localKey, pw, keyErrs, appSizeOnLoad]
|
[localKey, pw, keyErrs]
|
||||||
);
|
);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
@ -4,13 +4,13 @@ import Loader from "../components/Loader";
|
|||||||
import { useNavigate } from "react-router-dom";
|
import { useNavigate } from "react-router-dom";
|
||||||
import { sha256, toBytes } from "viem";
|
import { sha256, toBytes } from "viem";
|
||||||
import { Tooltip } from "../components/Tooltip";
|
import { Tooltip } from "../components/Tooltip";
|
||||||
|
import { redirectToHomepage } from "../utils/redirect-to-homepage";
|
||||||
|
|
||||||
interface LoginProps extends PageProps { }
|
interface LoginProps extends PageProps { }
|
||||||
|
|
||||||
function Login({
|
function Login({
|
||||||
pw,
|
pw,
|
||||||
setPw,
|
setPw,
|
||||||
appSizeOnLoad,
|
|
||||||
routers,
|
routers,
|
||||||
setRouters,
|
setRouters,
|
||||||
knsName,
|
knsName,
|
||||||
@ -57,23 +57,14 @@ function Login({
|
|||||||
if (result.status > 399) {
|
if (result.status > 399) {
|
||||||
throw new Error(await result.text());
|
throw new Error(await result.text());
|
||||||
}
|
}
|
||||||
|
redirectToHomepage();
|
||||||
|
|
||||||
const interval = setInterval(async () => {
|
|
||||||
const res = await fetch("/", { credentials: 'include' });
|
|
||||||
if (
|
|
||||||
res.status < 300 &&
|
|
||||||
Number(res.headers.get("content-length")) !== appSizeOnLoad
|
|
||||||
) {
|
|
||||||
clearInterval(interval);
|
|
||||||
window.location.replace("/");
|
|
||||||
}
|
|
||||||
}, 2000);
|
|
||||||
} catch (err: any) {
|
} catch (err: any) {
|
||||||
setKeyErrs([String(err)]);
|
setKeyErrs([String(err)]);
|
||||||
setLoading("");
|
setLoading("");
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
[pw, appSizeOnLoad]
|
[pw]
|
||||||
);
|
);
|
||||||
|
|
||||||
const isDirect = Boolean(routers?.length === 0);
|
const isDirect = Boolean(routers?.length === 0);
|
||||||
|
@ -5,6 +5,7 @@ import { Tooltip } from "../components/Tooltip";
|
|||||||
import { sha256, toBytes } from "viem";
|
import { sha256, toBytes } from "viem";
|
||||||
import { useSignTypedData, useAccount, useChainId } from 'wagmi'
|
import { useSignTypedData, useAccount, useChainId } from 'wagmi'
|
||||||
import { KIMAP } from "../abis";
|
import { KIMAP } from "../abis";
|
||||||
|
import { redirectToHomepage } from "../utils/redirect-to-homepage";
|
||||||
|
|
||||||
type SetPasswordProps = {
|
type SetPasswordProps = {
|
||||||
direct: boolean;
|
direct: boolean;
|
||||||
@ -12,7 +13,6 @@ type SetPasswordProps = {
|
|||||||
reset: boolean;
|
reset: boolean;
|
||||||
knsName: string;
|
knsName: string;
|
||||||
setPw: React.Dispatch<React.SetStateAction<string>>;
|
setPw: React.Dispatch<React.SetStateAction<string>>;
|
||||||
appSizeOnLoad: number;
|
|
||||||
nodeChainId: string;
|
nodeChainId: string;
|
||||||
closeConnect: () => void;
|
closeConnect: () => void;
|
||||||
};
|
};
|
||||||
@ -23,7 +23,6 @@ function SetPassword({
|
|||||||
pw,
|
pw,
|
||||||
reset,
|
reset,
|
||||||
setPw,
|
setPw,
|
||||||
appSizeOnLoad,
|
|
||||||
}: SetPasswordProps) {
|
}: SetPasswordProps) {
|
||||||
const [pw2, setPw2] = useState("");
|
const [pw2, setPw2] = useState("");
|
||||||
const [error, setError] = useState("");
|
const [error, setError] = useState("");
|
||||||
@ -103,25 +102,15 @@ function SetPassword({
|
|||||||
const base64String = await result.json();
|
const base64String = await result.json();
|
||||||
|
|
||||||
downloadKeyfile(knsName, base64String);
|
downloadKeyfile(knsName, base64String);
|
||||||
|
redirectToHomepage();
|
||||||
|
|
||||||
const interval = setInterval(async () => {
|
|
||||||
const res = await fetch("/", { credentials: 'include' });
|
|
||||||
|
|
||||||
if (
|
|
||||||
res.status < 300 &&
|
|
||||||
Number(res.headers.get("content-length")) !== appSizeOnLoad
|
|
||||||
) {
|
|
||||||
clearInterval(interval);
|
|
||||||
window.location.replace("/");
|
|
||||||
}
|
|
||||||
}, 2000);
|
|
||||||
} catch {
|
} catch {
|
||||||
alert("There was an error setting your password, please try again.");
|
alert("There was an error setting your password, please try again.");
|
||||||
setLoading(false);
|
setLoading(false);
|
||||||
}
|
}
|
||||||
}, 500);
|
}, 500);
|
||||||
},
|
},
|
||||||
[appSizeOnLoad, direct, pw, pw2, reset, knsName]
|
[direct, pw, pw2, reset, knsName]
|
||||||
);
|
);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
9
kinode/src/register-ui/src/utils/redirect-to-homepage.ts
Normal file
9
kinode/src/register-ui/src/utils/redirect-to-homepage.ts
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
export const redirectToHomepage = () => {
|
||||||
|
const interval = setInterval(async () => {
|
||||||
|
const res = await fetch("/version", { credentials: 'include' });
|
||||||
|
if (res.status == 200) {
|
||||||
|
clearInterval(interval);
|
||||||
|
window.location.replace("/");
|
||||||
|
}
|
||||||
|
}, 500);
|
||||||
|
};
|
Loading…
Reference in New Issue
Block a user