actually redirects to terms

This commit is contained in:
Luke Berndt
2024-07-09 07:27:51 -04:00
parent 1cb336f258
commit bb72f1e538
2 changed files with 122 additions and 117 deletions

View File

@@ -8,7 +8,7 @@ import { useNavigate, useLocation } from 'react-router-dom';
*/ */
const Restricted = ({ children }) => { const Restricted = ({ children }) => {
const { authenticated, hasAuthenticated,terms } = useSelector((state) => state.user); const { authenticated, hasAuthenticated, terms } = useSelector((state) => state.user);
const dispatch = useDispatch(); const dispatch = useDispatch();
const navigate = useNavigate(); const navigate = useNavigate();
const location = useLocation(); const location = useLocation();
@@ -22,9 +22,10 @@ const Restricted = ({ children }) => {
if (authenticated) { if (authenticated) {
if ((pathname != "/terms") && (terms != 1.1)) { if ((pathname != "/terms") && (terms != 1.1)) {
navigate("/terms") navigate("/terms")
} } else {
return children; return children;
} }
}
else { else {
navigate("/login") navigate("/login")
} }

View File

@@ -1,7 +1,7 @@
import { useState } from "react"; import { useState } from "react";
import { useNavigate, useSearchParams, Link } from 'react-router-dom'; import { useNavigate, useSearchParams, Link, useLocation } from 'react-router-dom';
import { useSelector, useDispatch } from 'react-redux'
import { loginUser } from "../features/user/userSlice"; import { loginUser } from "../features/user/userSlice";
import { useDispatch } from 'react-redux';
import { import {
Container, Container,
Header, Header,
@@ -28,20 +28,24 @@ const forgotStyle = {
const Login = (props) => { const Login = (props) => {
const { terms } = useSelector((state) => state.user);
const [loginMessage, setLoginMessage] = useState(""); const [loginMessage, setLoginMessage] = useState("");
const [email, setEmail] = useState(""); const [email, setEmail] = useState("");
const [password, setPassword] = useState(""); const [password, setPassword] = useState("");
const navigate = useNavigate(); const navigate = useNavigate();
let [searchParams] = useSearchParams(); let [searchParams] = useSearchParams();
const nextLocation = searchParams.get("nextLocation"); const nextLocation = searchParams.get("nextLocation");
const location = useLocation();
const { hash, pathname, search } = location;
const dispatch = useDispatch(); const dispatch = useDispatch();
const loginSubmit = async (event) => { const loginSubmit = async (event) => {
event.preventDefault(); event.preventDefault();
const result = await dispatch(loginUser({email,password})).unwrap(); const result = await dispatch(loginUser({ email, password })).unwrap();
if (result.success) { if (result.success) {
if ((pathname != "/terms") && (terms != 1.1)) {
if (nextLocation) { navigate("/terms")
} else if (nextLocation) {
switch (nextLocation) { switch (nextLocation) {
case "frontend": case "frontend":
window.location = process.env.REACT_APP_FRONTEND_SERVER; window.location = process.env.REACT_APP_FRONTEND_SERVER;
@@ -73,7 +77,7 @@ const Login = (props) => {
} }
} }
let loginMessageDisplay =(<></>) let loginMessageDisplay = (<></>)
if (loginMessage) { if (loginMessage) {
loginMessageDisplay = ( loginMessageDisplay = (
@@ -135,7 +139,7 @@ const Login = (props) => {
<Button <Button
size="large" size="large"
content="Register" content="Register"
onClick={()=>navigate("/register")} onClick={() => navigate("/register")}
fluid fluid
/> />
<Divider style={dividerStyle} horizontal>Or</Divider> <Divider style={dividerStyle} horizontal>Or</Divider>
@@ -179,7 +183,7 @@ const Login = (props) => {
</Grid> </Grid>
</Container> </Container>
); );
} }
export default Login; export default Login;