diff --git a/components/frontend-react/src/components/Appbar.js b/components/frontend-react/src/components/Appbar.js index 23a4e90d..1a57591b 100644 --- a/components/frontend-react/src/components/Appbar.js +++ b/components/frontend-react/src/components/Appbar.js @@ -82,7 +82,6 @@ const BassaAppBar = props => { const handleNavigationButtons = route => { switch (route) { case 'logout': - sessionStorage.removeItem('token'); props.logoutUser(); props.history.replace('/'); break; @@ -207,7 +206,4 @@ const mapDispatchToProps = dispatch => ({ logoutUser: () => dispatch(logoutUser()) }); -export default connect( - null, - mapDispatchToProps -)(withRouter(BassaAppBar)); +export default connect(null, mapDispatchToProps)(withRouter(BassaAppBar)); diff --git a/components/frontend-react/src/reducers/userReducer.js b/components/frontend-react/src/reducers/userReducer.js index d619390d..c14214b5 100644 --- a/components/frontend-react/src/reducers/userReducer.js +++ b/components/frontend-react/src/reducers/userReducer.js @@ -2,7 +2,7 @@ import { userActions } from '../constants'; const initialState = { isUserAdmin: false, - isloggedIn: false, + isloggedIn: !!sessionStorage.getItem('token'), hasAuthFailed: false, hasSignupFailed: false, hasSignupSuccessful: false, @@ -17,8 +17,10 @@ const initialState = { const userReducer = (state = initialState, action) => { switch (action.type) { case userActions.AUTH_SUCCESS: - return { ...state, isloggedIn: true, username: action.username }; - + if (sessionStorage.getItem('token')) { + return { ...state, isloggedIn: true, username: action.username }; + } + return { ...state }; case userActions.CHECK_ADMIN: if (action.payload === '0') { return { ...state, isUserAdmin: true }; @@ -26,7 +28,8 @@ const userReducer = (state = initialState, action) => { return { ...state }; case userActions.LOGOUT_USER: - return { state: initialState, isloggedIn: false }; + sessionStorage.removeItem('token'); + return { state: initialState, isloggedIn: false, authLevel: null }; case userActions.ADD_NEW_USER: return { ...state, details: action.details };