Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix logged in error on refreshing in react app #879

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 1 addition & 5 deletions components/frontend-react/src/components/Appbar.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,6 @@ const BassaAppBar = props => {
const handleNavigationButtons = route => {
switch (route) {
case 'logout':
sessionStorage.removeItem('token');
props.logoutUser();
props.history.replace('/');
break;
Expand Down Expand Up @@ -207,7 +206,4 @@ const mapDispatchToProps = dispatch => ({
logoutUser: () => dispatch(logoutUser())
});

export default connect(
null,
mapDispatchToProps
)(withRouter(BassaAppBar));
export default connect(null, mapDispatchToProps)(withRouter(BassaAppBar));
11 changes: 7 additions & 4 deletions components/frontend-react/src/reducers/userReducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { userActions } from '../constants';

const initialState = {
isUserAdmin: false,
isloggedIn: false,
isloggedIn: !!sessionStorage.getItem('token'),
hasAuthFailed: false,
hasSignupFailed: false,
hasSignupSuccessful: false,
Expand All @@ -17,16 +17,19 @@ 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 };
}
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 };
Expand Down