diff --git a/src/Components/MenuList.js b/src/Components/MenuList.js index 796b57b386e93056825e0ced50a2b1d8b4a4cae0..402fa2e747ff3f45f7357d675d64db260472f556 100644 --- a/src/Components/MenuList.js +++ b/src/Components/MenuList.js @@ -28,7 +28,9 @@ import { Store } from '../Store'; import { Redirect } from "react-router-dom"; import Profile from '../img/default_profile0.png' import styled from 'styled-components' -import {apiDomain} from '../env.js' +import {apiDomain, apiUrl} from '../env.js' +import {getAxiosConfig} from './HelperFunctions/getAxiosConfig' +import axios from 'axios' const iconStyles = { fontSize : "xxx-large", @@ -56,20 +58,29 @@ export default function MenuList(props) { }; const handleLogout = () => { - localStorage.removeItem('@portalmec/username'); - sessionStorage.removeItem('@portalmec/uid'); - sessionStorage.removeItem('@portalmec/senha'); - dispatch( { - type: 'USER_LOGGED_OUT', - userLoggedOut: !state.userIsLoggedIn, - login: { - username : '', - email : '', - accessToken : '', - client : '' + let config = getAxiosConfig() + axios.delete(`${apiUrl}/auth/sign_out`, config).then( + (res) => { + + localStorage.removeItem('@portalmec/username'); + sessionStorage.removeItem('@portalmec/uid'); + sessionStorage.removeItem('@portalmec/senha'); + dispatch( { + type: 'USER_LOGGED_OUT', + userLoggedOut: !state.userIsLoggedIn, + login: { + username : '', + email : '', + accessToken : '', + client : '' } - } + }) + }, + (err) => { + console.log(err) + } ) + } return ( diff --git a/src/Components/MobileDrawerMenu.js b/src/Components/MobileDrawerMenu.js index 82d708bd09905fb5bba06f931b3e41dfba4dea29..479ccc04875eeb926894a8237d9d31434916c24d 100644 --- a/src/Components/MobileDrawerMenu.js +++ b/src/Components/MobileDrawerMenu.js @@ -31,13 +31,15 @@ import ExitToAppIcon from '@material-ui/icons/ExitToApp' import { Button } from '@material-ui/core'; import MenuItem from '@material-ui/core/MenuItem'; import DefaultAvatar from '../img/default_profile0.png' -import {apiDomain} from '../env.js' import CloudUploadIcon from '@material-ui/icons/CloudUpload'; import CloudDoneIcon from '@material-ui/icons/CloudDone'; import HistoryIcon from '@material-ui/icons/History'; import FavoriteBorderIcon from '@material-ui/icons/FavoriteBorder'; import FolderOpenIcon from '@material-ui/icons/FolderOpen'; import SettingsIcon from '@material-ui/icons/Settings'; +import {apiDomain, apiUrl} from '../env.js' +import {getAxiosConfig} from './HelperFunctions/getAxiosConfig' +import axios from 'axios' export default function MobileDrawerMenu (props) { const {state, dispatch} = useContext(Store) @@ -76,19 +78,27 @@ export default function MobileDrawerMenu (props) { {/*dispatches log out actions to Store.js*/} const handleLogout = () => { - sessionStorage.removeItem('@portalmec/username'); - sessionStorage.removeItem('@portalmec/uid'); - sessionStorage.removeItem('@portalmec/senha'); - dispatch( { - type: 'USER_LOGGED_OUT', - userLoggedOut: !state.userIsLoggedIn, - login: { - username : '', - email : '', - accessToken : '', - client : '' + let config = getAxiosConfig() + axios.delete(`${apiUrl}/auth/sign_out`, config).then( + (res) => { + + localStorage.removeItem('@portalmec/username'); + sessionStorage.removeItem('@portalmec/uid'); + sessionStorage.removeItem('@portalmec/senha'); + dispatch( { + type: 'USER_LOGGED_OUT', + userLoggedOut: !state.userIsLoggedIn, + login: { + username : '', + email : '', + accessToken : '', + client : '' } - } + }) + }, + (err) => { + console.log(err) + } ) }