Skip to content
Snippets Groups Projects
Commit 670a53f9 authored by Tamás Szabó's avatar Tamás Szabó
Browse files

logout

parent 974b77ec
No related branches found
No related tags found
No related merge requests found
import ax from 'axios'; import ax from 'axios';
import { GET_USERDATA, PROFILE_CHANGE, GROUP_CHANGE } from './types'; import { GET_USERDATA, PROFILE_CHANGE, GROUP_CHANGE, LOGOUT } from './types';
const axios = ax.create({ const axios = ax.create({
xsrfCookieName: 'csrftoken', xsrfCookieName: 'csrftoken',
...@@ -45,3 +45,12 @@ export const submitRegistration = ({ ...@@ -45,3 +45,12 @@ export const submitRegistration = ({
} }
} }
); );
export const logout = () => (
async (dispatch) => {
const response = await axios.get('/api/v1/logout/');
if (response) {
dispatch({ action: LOGOUT });
}
}
);
...@@ -9,7 +9,7 @@ import { ...@@ -9,7 +9,7 @@ import {
Image, Image,
} from 'semantic-ui-react'; } from 'semantic-ui-react';
import { connect } from 'react-redux'; import { connect } from 'react-redux';
import { getUserData } from '../actions'; import { getUserData, logout } from '../actions';
import KSZKlogo from './images/kszk_logo.svg'; import KSZKlogo from './images/kszk_logo.svg';
const FixedMenu = ({ user }) => ( const FixedMenu = ({ user }) => (
...@@ -31,7 +31,10 @@ const FixedMenu = ({ user }) => ( ...@@ -31,7 +31,10 @@ const FixedMenu = ({ user }) => (
<Menu.Item className='item'> <Menu.Item className='item'>
{ {
user.id ? user.id ?
<Button as={Link} to='/profile'>Profilom</Button> <div>
<Button as={Link} to='/profile'>Profilom</Button>
<Button onClick={() => this.props.logout()}>Kijelentkezés</Button>
</div>
: :
<Button href='/api/v1/login/authsch/'>Bejelentkezés</Button> <Button href='/api/v1/login/authsch/'>Bejelentkezés</Button>
} }
...@@ -114,4 +117,4 @@ const mapStateToProps = ({ user }) => ({ ...@@ -114,4 +117,4 @@ const mapStateToProps = ({ user }) => ({
user, user,
}); });
export default connect(mapStateToProps, { getUserData })(Header); export default connect(mapStateToProps, { getUserData, logout })(Header);
...@@ -2,6 +2,7 @@ import { ...@@ -2,6 +2,7 @@ import {
GET_USERDATA, GET_USERDATA,
PROFILE_CHANGE, PROFILE_CHANGE,
GROUP_CHANGE, GROUP_CHANGE,
LOGOUT,
} from '../actions/types'; } from '../actions/types';
const INITIAL_STATE = { const INITIAL_STATE = {
...@@ -15,6 +16,8 @@ export default (state = INITIAL_STATE, action) => { ...@@ -15,6 +16,8 @@ export default (state = INITIAL_STATE, action) => {
return { ...state, [action.target]: action.payload }; return { ...state, [action.target]: action.payload };
case GROUP_CHANGE: case GROUP_CHANGE:
return { ...state, groups: action.payload }; return { ...state, groups: action.payload };
case LOGOUT:
return INITIAL_STATE;
default: default:
return state; return state;
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment