diff options
author | Galen Guyer <galen@galenguyer.com> | 2022-08-31 14:19:06 -0400 |
---|---|---|
committer | Galen Guyer <galen@galenguyer.com> | 2022-08-31 14:19:06 -0400 |
commit | 2d803fce5746fc2495e05d837e663b56fe392ea0 (patch) | |
tree | 50a4654532be51c3b72d7371388bf8f5dae055cc | |
parent | 641bcfe174daf231209acc2ecee1dfa681471089 (diff) |
Add links to signup/login pages in opposing page
-rw-r--r-- | src/routes/Login.js | 4 | ||||
-rw-r--r-- | src/routes/SignUp.js | 24 |
2 files changed, 26 insertions, 2 deletions
diff --git a/src/routes/Login.js b/src/routes/Login.js index e39d01e..afdd88b 100644 --- a/src/routes/Login.js +++ b/src/routes/Login.js @@ -8,6 +8,7 @@ import { useFeatures } from "../hooks/useFeatures"; import { isExpired } from "react-jwt"; import { styled } from "@stitches/react"; import { debounce } from "lodash"; +import { Link } from "react-router-dom"; const Flex = styled("div", { display: "flex", @@ -137,6 +138,9 @@ function Login(props) { Log In {"\u2794"} </Button> </AlignRight> + <center> + {features.signup && (<p>Don't have an account? <Link to="/signup">Sign up!</Link></p>)} + </center> </LoginCard> </Flex> ); diff --git a/src/routes/SignUp.js b/src/routes/SignUp.js index f223dad..5b64cc0 100644 --- a/src/routes/SignUp.js +++ b/src/routes/SignUp.js @@ -2,10 +2,12 @@ import { styled } from "@stitches/react"; import Button from "../uikit/Button.js"; import Input from "../uikit/Input.js"; import { debounce } from "lodash"; -import { useState } from "react"; +import { useEffect, useState } from "react"; import { useAuth } from "../hooks/useAuth.js"; -import { useNavigate } from "react-router-dom"; +import { useNavigate, useLocation } from "react-router-dom"; import { useFeatures } from "../hooks/useFeatures.js"; +import { Link } from "react-router-dom"; +import { isExpired } from "react-jwt"; const Flex = styled("div", { display: "flex", @@ -116,6 +118,16 @@ export function SignUp() { }); }; + let location = useLocation(); + + let from = location.state?.from?.pathname || "/zones"; + + useEffect(() => { + if (auth.token && !isExpired(auth.token)) { + navigate(from, { replace: true }); + } + }, [auth.token, from, navigate]); + if (!features.signup) { return ( <Flex> @@ -124,6 +136,9 @@ export function SignUp() { <Subtitle>Sign Up</Subtitle> <center> <p>Sorry, but sign-ups are currently disabled.</p> + <p> + If you have an account, you can <Link to="/login">sign in.</Link> + </p> </center> </LoginCard> </Flex> @@ -167,6 +182,11 @@ export function SignUp() { Sign Up {"\u2794"} </Button> </AlignRight> + <center> + <p> + If you have an account, you can <Link to="/login">sign in.</Link> + </p> + </center> </LoginCard> </Flex> ); |