Merge pull request #1643 from SkynetLabs/login-link-fix

Simple fix for Login URL formatting of double slash
This commit is contained in:
Karol Wypchło 2022-02-04 11:38:55 +01:00 committed by GitHub
commit 29f7502d90
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 13 additions and 12 deletions

View File

@ -26,7 +26,7 @@ const Navigation = ({ mode, uri }) => {
const windowSize = useWindowSize(); const windowSize = useWindowSize();
const isWindowTop = useWindowTop(); const isWindowTop = useWindowTop();
const { data: accounts } = useAccounts(); const { data: accounts } = useAccounts();
const accountsUrl = useAccountsUrl(); const createAccountsUrl = useAccountsUrl();
React.useEffect(() => { React.useEffect(() => {
setOpen(false); setOpen(false);
@ -90,18 +90,18 @@ const Navigation = ({ mode, uri }) => {
{showLoginNavigation && ( {showLoginNavigation && (
<> <>
<Link href={`${accountsUrl}/auth/login`} className="button-link-primary"> <Link href={createAccountsUrl("/auth/login")} className="button-link-primary">
Log in Log in
</Link> </Link>
<Link href={`${accountsUrl}/auth/registration`} className="button-primary"> <Link href={createAccountsUrl("/auth/registration")} className="button-primary">
Sign up Sign up
</Link> </Link>
</> </>
)} )}
{showAccountNavigation && ( {showAccountNavigation && (
<Link href={accountsUrl} className="button-primary"> <Link href={createAccountsUrl()} className="button-primary">
My account My account
</Link> </Link>
)} )}
@ -144,18 +144,18 @@ const Navigation = ({ mode, uri }) => {
<div className="flex items-center justify-center px-4 space-x-6"> <div className="flex items-center justify-center px-4 space-x-6">
{showLoginNavigation && ( {showLoginNavigation && (
<> <>
<Link href={`${accountsUrl}/auth/login`} className="button-secondary-light"> <Link href={createAccountsUrl("auth/login")} className="button-secondary-light">
Log in Log in
</Link> </Link>
<Link href={`${accountsUrl}/auth/registration`} className="button-primary"> <Link href={createAccountsUrl("/auth/registration")} className="button-primary">
Sign up Sign up
</Link> </Link>
</> </>
)} )}
{showAccountNavigation && ( {showAccountNavigation && (
<Link href={accountsUrl} className="button-primary"> <Link href={createAccountsUrl()} className="button-primary">
My account My account
</Link> </Link>
)} )}

View File

@ -22,11 +22,11 @@ const getRootDirectory = (file) => {
}; };
const RegistrationLink = () => { const RegistrationLink = () => {
const accountsUrl = useAccountsUrl(); const createAccountsUrl = useAccountsUrl();
return ( return (
<Link <Link
href={`${accountsUrl}/auth/registration`} href={createAccountsUrl("auth/registration")}
className="uppercase underline-primary hover:text-primary transition-colors duration-200" className="uppercase underline-primary hover:text-primary transition-colors duration-200"
> >
Sign up Sign up
@ -35,11 +35,11 @@ const RegistrationLink = () => {
}; };
const LogInLink = () => { const LogInLink = () => {
const accountsUrl = useAccountsUrl(); const createAccountsUrl = useAccountsUrl();
return ( return (
<Link <Link
href={`${accountsUrl}/auth/login`} href={createAccountsUrl("auth/login")}
className="uppercase underline-primary hover:text-primary transition-colors duration-200" className="uppercase underline-primary hover:text-primary transition-colors duration-200"
> >
Log in Log in

View File

@ -3,6 +3,7 @@ import skynetClient from "./skynetClient";
export default function useAccountsUrl() { export default function useAccountsUrl() {
const [url, setUrl] = React.useState(""); const [url, setUrl] = React.useState("");
const createAccountsUrl = React.useCallback((path = "") => url && new URL(path, url).toString(), [url]);
React.useEffect(() => { React.useEffect(() => {
(async function resolve() { (async function resolve() {
@ -14,5 +15,5 @@ export default function useAccountsUrl() {
})(); })();
}, [setUrl]); }, [setUrl]);
return url; return createAccountsUrl;
} }