use authenticated status

This commit is contained in:
Karol Wypchlo 2021-04-08 13:10:58 +02:00
parent 3021032464
commit dda1e5f122
3 changed files with 42 additions and 12 deletions

View File

@ -60,6 +60,7 @@
"react-use": "^17.2.3", "react-use": "^17.2.3",
"skynet-js": "^3.0.2", "skynet-js": "^3.0.2",
"stream-browserify": "^3.0.0", "stream-browserify": "^3.0.0",
"swr": "^0.5.5",
"tailwindcss": "^2.1.1" "tailwindcss": "^2.1.1"
}, },
"devDependencies": { "devDependencies": {

View File

@ -2,6 +2,7 @@ import * as React from "react";
import PropTypes from "prop-types"; import PropTypes from "prop-types";
import Link from "../Link"; import Link from "../Link";
import classnames from "classnames"; import classnames from "classnames";
import useAuthenticatedStatus from "../../services/useAuthenticatedStatus";
import LogoWhiteText from "../Icons/LogoWhiteText.svg"; import LogoWhiteText from "../Icons/LogoWhiteText.svg";
import LogoBlackText from "../Icons/LogoBlackText.svg"; import LogoBlackText from "../Icons/LogoBlackText.svg";
import MenuMobile from "../Icons/MenuMobile.svg"; import MenuMobile from "../Icons/MenuMobile.svg";
@ -27,6 +28,7 @@ const Navigation = ({ mode, uri }) => {
const [open, setOpen] = React.useState(false); const [open, setOpen] = React.useState(false);
const windowSize = useWindowSize(); const windowSize = useWindowSize();
const isWindowTop = useWindowTop(); const isWindowTop = useWindowTop();
const { authenticated } = useAuthenticatedStatus();
React.useEffect(() => { React.useEffect(() => {
setOpen(false); setOpen(false);
@ -85,12 +87,24 @@ const Navigation = ({ mode, uri }) => {
{title} {title}
</Link> </Link>
))} ))}
{!authenticated && (
<Link href="https://account.siasky.net" className="button-link-primary"> <Link href="https://account.siasky.net" className="button-link-primary">
Log in Log in
</Link> </Link>
)}
{!authenticated && (
<Link href="https://account.siasky.net/auth/registration" className="button-primary"> <Link href="https://account.siasky.net/auth/registration" className="button-primary">
Sign up Sign up
</Link> </Link>
)}
{authenticated && (
<Link href="https://account.siasky.net" className="button-primary">
Dashboard
</Link>
)}
</div> </div>
</div> </div>
@ -128,13 +142,23 @@ const Navigation = ({ mode, uri }) => {
</div> </div>
<div className="pt-12 pb-8 border-t border-palette-500"> <div className="pt-12 pb-8 border-t border-palette-500">
<div className="flex items-center justify-center px-4 space-x-6"> <div className="flex items-center justify-center px-4 space-x-6">
{!authenticated && (
<Link href="https://account.siasky.net" className="button-secondary-light"> <Link href="https://account.siasky.net" className="button-secondary-light">
Log in Log in
</Link> </Link>
)}
{!authenticated && (
<Link href="https://account.siasky.net/auth/registration" className="button-primary"> <Link href="https://account.siasky.net/auth/registration" className="button-primary">
Sign up Sign up
</Link> </Link>
)}
{authenticated && (
<Link href="https://account.siasky.net" className="button-primary">
Dashboard
</Link>
)}
</div> </div>
</div> </div>
</div> </div>

View File

@ -0,0 +1,5 @@
import useSWR from "swr";
export default function useAuthenticatedStatus() {
return useSWR("/__internal/do/not/use", (url) => (await fetch(url)).json());
}