Browse Source

fixed redirection after logout

Skylsmoi 6 years ago
parent
commit
b8e98d41ad
1 changed files with 5 additions and 3 deletions
  1. 5 3
      frontend/src/container/Header.jsx

+ 5 - 3
frontend/src/container/Header.jsx View File

1
 import React from 'react'
1
 import React from 'react'
2
 import { connect } from 'react-redux'
2
 import { connect } from 'react-redux'
3
+import { withRouter } from 'react-router'
3
 import i18n from '../i18n.js'
4
 import i18n from '../i18n.js'
4
 import appFactory from '../appFactory.js'
5
 import appFactory from '../appFactory.js'
5
 import { translate } from 'react-i18next'
6
 import { translate } from 'react-i18next'
21
 import {
22
 import {
22
   postUserLogout
23
   postUserLogout
23
 } from '../action-creator.async.js'
24
 } from '../action-creator.async.js'
24
-import { COOKIE } from '../helper.js'
25
+import { COOKIE, PAGE } from '../helper.js'
25
 
26
 
26
 class Header extends React.Component {
27
 class Header extends React.Component {
27
   handleClickLogo = () => {}
28
   handleClickLogo = () => {}
42
   handleClickHelp = () => {}
43
   handleClickHelp = () => {}
43
 
44
 
44
   handleClickLogout = async () => {
45
   handleClickLogout = async () => {
45
-    const { dispatch, t } = this.props
46
+    const { history, dispatch, t } = this.props
46
 
47
 
47
     const fetchPostUserLogout = await dispatch(postUserLogout())
48
     const fetchPostUserLogout = await dispatch(postUserLogout())
48
     if (fetchPostUserLogout.status === 204) {
49
     if (fetchPostUserLogout.status === 204) {
50
       Cookies.remove(COOKIE.USER_AUTH)
51
       Cookies.remove(COOKIE.USER_AUTH)
51
 
52
 
52
       dispatch(setUserDisconnected())
53
       dispatch(setUserDisconnected())
54
+      history.push(PAGE.LOGIN)
53
     } else {
55
     } else {
54
       dispatch(newFlashMessage(t('Disconnection error', 'danger')))
56
       dispatch(newFlashMessage(t('Disconnection error', 'danger')))
55
     }
57
     }
107
 }
109
 }
108
 
110
 
109
 const mapStateToProps = ({ lang, user }) => ({ lang, user })
111
 const mapStateToProps = ({ lang, user }) => ({ lang, user })
110
-export default connect(mapStateToProps)(translate()(appFactory(Header)))
112
+export default withRouter(connect(mapStateToProps)(translate()(appFactory(Header))))