From 670a53f96000a5fb65c903632c175919c1329c0b Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Tam=C3=A1s=20Szab=C3=B3?= <tamas@szaboo.com>
Date: Sat, 3 Feb 2018 21:02:23 +0100
Subject: [PATCH] logout

---
 src/actions/auth.js         | 11 ++++++++++-
 src/components/Header.js    |  9 ++++++---
 src/reducers/UserReducer.js |  3 +++
 3 files changed, 19 insertions(+), 4 deletions(-)

diff --git a/src/actions/auth.js b/src/actions/auth.js
index eecdeba..ba8f7d9 100644
--- a/src/actions/auth.js
+++ b/src/actions/auth.js
@@ -1,5 +1,5 @@
 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({
   xsrfCookieName: 'csrftoken',
@@ -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 });
+    }
+  }
+);
diff --git a/src/components/Header.js b/src/components/Header.js
index c35d7b1..e89414b 100644
--- a/src/components/Header.js
+++ b/src/components/Header.js
@@ -9,7 +9,7 @@ import {
   Image,
 } from 'semantic-ui-react';
 import { connect } from 'react-redux';
-import { getUserData } from '../actions';
+import { getUserData, logout } from '../actions';
 import KSZKlogo from './images/kszk_logo.svg';
 
 const FixedMenu = ({ user }) => (
@@ -31,7 +31,10 @@ const FixedMenu = ({ user }) => (
         <Menu.Item className='item'>
           {
             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>
           }
@@ -114,4 +117,4 @@ const mapStateToProps = ({ user }) => ({
   user,
 });
 
-export default connect(mapStateToProps, { getUserData })(Header);
+export default connect(mapStateToProps, { getUserData, logout })(Header);
diff --git a/src/reducers/UserReducer.js b/src/reducers/UserReducer.js
index 839a47e..607f6dc 100644
--- a/src/reducers/UserReducer.js
+++ b/src/reducers/UserReducer.js
@@ -2,6 +2,7 @@ import {
   GET_USERDATA,
   PROFILE_CHANGE,
   GROUP_CHANGE,
+  LOGOUT,
 } from '../actions/types';
 
 const INITIAL_STATE = {
@@ -15,6 +16,8 @@ export default (state = INITIAL_STATE, action) => {
       return { ...state, [action.target]: action.payload };
     case GROUP_CHANGE:
       return { ...state, groups: action.payload };
+    case LOGOUT:
+      return INITIAL_STATE;
     default:
       return state;
   }
-- 
GitLab