Skip to content

Commit

Permalink
Added routing and logout
Browse files Browse the repository at this point in the history
  • Loading branch information
MinhPhan8803 committed Nov 27, 2022
1 parent 1df1b36 commit cc6e28d
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 3 deletions.
16 changes: 16 additions & 0 deletions src/frontend/src/components/user/changeInfo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,20 @@ export function changePhone(new_phone: string, username: string) {
console.log(error.response.headers);
}
});
}

export function logout() {
axios({
url: 'http://127.0.0.1:5000/logout'
})
.then((response) => {
console.log(response);
})
.catch((error) => {
if (error.response) {
console.log(error.response);
console.log(error.response.status);
console.log(error.response.headers);
}
});
}
7 changes: 6 additions & 1 deletion src/frontend/src/pages/Login.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
import PersonIcon from '@mui/icons-material/Person';
import axios from 'axios';
import { useState } from 'react';
import { useNavigate } from "react-router-dom";

function sendData(user: string, password: string) {
axios({
Expand All @@ -35,6 +36,7 @@ function sendData(user: string, password: string) {
}

export default function Login() {
const navigate = useNavigate();
const [user, setUser] = useState('');
const [password, setPassword] = useState('');

Expand Down Expand Up @@ -74,7 +76,10 @@ export default function Login() {
color="primary"
variant="contained"
style={btnstyle}
onClick={() => sendData(user, password)}
onClick={() => {
sendData(user, password)
navigate('/')
}}
fullWidth
>
Sign in
Expand Down
4 changes: 2 additions & 2 deletions src/frontend/src/pages/User.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import AccountCircleIcon from '@mui/icons-material/AccountCircle';
import PersonIcon from '@mui/icons-material/Person';
import getReviewedApts from '../components/user/getReviewedApts';
import getUser from '../components/user/getUser';
import {changeEmail, changePhone} from '../components/user/changeInfo';
import {changeEmail, changePhone, logout} from '../components/user/changeInfo';
import { useState } from 'react';
import { useNavigate } from "react-router-dom";

Expand Down Expand Up @@ -58,7 +58,7 @@ export default function User() {
</Grid>
<Grid item>
<Box display="flex" justifyContent="flex-end" alignItems="flex-end">
<Button sx={{ color: '#fff' }}>
<Button sx={{ color: '#fff' }} onClick={() => logout()}>
Logout
</Button>
</Box>
Expand Down

0 comments on commit cc6e28d

Please sign in to comment.