Updated login stuff plus logout button works now

This commit is contained in:
Ava DeCroix
2023-04-29 22:52:09 -04:00
parent 86ecb279de
commit 24c5eb4b5e
3 changed files with 23 additions and 7 deletions

View File

@@ -12,7 +12,7 @@ import {
useNavigate, useNavigate,
} from 'react-router-dom'; } from 'react-router-dom';
ReactSession.setStoreType("localStorage"); ReactSession.setStoreType("sessionStorage");
function App() { function App() {

View File

@@ -34,6 +34,10 @@ export function Login() {
navigate('/CreateAccount'); navigate('/CreateAccount');
} }
const navigateHome = () => {
navigate('/Plan');
}
const [data,setData] = useState({ const [data,setData] = useState({
net_id:"", net_id:"",
password:"" password:""
@@ -50,11 +54,12 @@ const [data,setData] = useState({
console.log(data); console.log(data);
console.log(net_id[0]) console.log(net_id[0])
login(); login();
ReactSession.set("username", net_id[0]);
ReactSession.set("password", password[0]);
} }
const setSession = () => {
ReactSession.set("net_id", net_id[0]);
}
const getHello = () => { const getHello = () => {
@@ -66,7 +71,12 @@ const getHello = () => {
const login = () => { const login = () => {
Axios.post("http://3.219.93.142:8000/api/auth", {net_id: net_id[0], password: password[0],}).then((response) => { Axios.post("http://3.219.93.142:8000/api/auth", {net_id: net_id[0], password: password[0],}).then((response) => {
console.log(response); console.log(response);
console.log(response.status) console.log(response.status);
if (response.status === 200){
setSession();
navigateHome();
}
}); });
}; };

View File

@@ -21,7 +21,7 @@ import MenuIcon from '@mui/material/Menu'
import MenuItem from '@mui/material/MenuItem'; import MenuItem from '@mui/material/MenuItem';
import {red, green, lightBlue, lightGreen} from '@mui/material/colors'; import {red, green, lightBlue, lightGreen} from '@mui/material/colors';
import { ThemeProvider, createTheme } from '@mui/material/styles'; import { ThemeProvider, createTheme } from '@mui/material/styles';
import { ReactSession } from 'react-client-session';
@@ -50,6 +50,12 @@ function MyPlan() {
} }
const navigateLogin = () => { const navigateLogin = () => {
navigate('/'); navigate('/');
}
const logout = () => {
ReactSession.set("net_id", "");
navigateLogin();
} }
return ( return (
@@ -67,7 +73,7 @@ const navigateLogin = () => {
</Button> </Button>
<Button variant="h6"onClick={Past} > <Button variant="h6"onClick={Past} >
Past Plans</Button> Past Plans</Button>
<Button variant="h6" color="main" component="div" onClick={navigateLogin} sx={{ <Button variant="h6" color="main" component="div" onClick={logout} sx={{
':hover': { ':hover': {
bgcolor: '#ffc6c4', // theme.palette.primary.main bgcolor: '#ffc6c4', // theme.palette.primary.main
color: 'red', color: 'red',