Parcourir la source

Fixed user

master
Lazar Kostic il y a 2 ans
Parent
révision
45210385e8

+ 3
- 3
store/actions/user/userActionConstants.js Voir le fichier

@@ -1,3 +1,3 @@
export const SET_USER = 'SET_USER';
export const SET_USER_ERROR = 'SET_USER_ERROR';
export const SET_USER = "SET_USER";
export const SET_USER_ERROR = "SET_USER_ERROR";
export const RESET_USER_STATE = "RESET_USER_STATE";

+ 5
- 0
store/actions/user/userActions.js Voir le fichier

@@ -1,4 +1,5 @@
import {
RESET_USER_STATE,
SET_USER,
SET_USER_ERROR,
} from './userActionConstants';
@@ -12,3 +13,7 @@ export const setUserError = (payload) => ({
type: SET_USER_ERROR,
payload,
});

export const resetUserState = () => ({
type: RESET_USER_STATE,
});

+ 9
- 3
store/reducers/user/userReducer.js Voir le fichier

@@ -1,8 +1,9 @@
import createReducer from '../../utils/createReducer';
import createReducer from "../../utils/createReducer";
import {
RESET_USER_STATE,
SET_USER,
SET_USER_ERROR,
} from '../../actions/user/userActionConstants';
} from "../../actions/user/userActionConstants";

const initialState = {
user: {},
@@ -12,8 +13,9 @@ export default createReducer(
{
[SET_USER]: setUser,
[SET_USER_ERROR]: setUserError,
[RESET_USER_STATE]: resetUser,
},
initialState,
initialState
);

function setUser(state, action) {
@@ -29,3 +31,7 @@ function setUserError(state, action) {
errorMessage: action.payload,
};
}

function resetUser() {
return initialState;
}

+ 8
- 6
store/saga/loginSaga.js Voir le fichier

@@ -5,20 +5,20 @@ import {
LOGOUT_USER,
REFRESH_TOKEN,
} from "../actions/login/loginActionConstants";
import { attemptLogin, logoutUserRequest } from "../../request/loginRequest";
import { attemptLogin, logoutUserRequest } from "@request/loginRequest";
import {
fetchUserError,
fetchUserSuccess,
resetLoginState,
} from "../actions/login/loginActions";
import { setUser } from "../actions/user/userActions";
import { resetUserState, setUser } from "../actions/user/userActions";
import { addHeaderToken, removeHeaderToken } from "../../request";
import {
JWT_REFRESH_TOKEN,
JWT_TOKEN,
} from "../../constants/localStorage";
import { storeData, getData, clearAll } from "../../service/asyncStorage";
import { rejectErrorCodeHelper } from "../../utils/rejectErrorMessageHelper";
} from "@constants/localStorage";
import { storeData, getData, removeData } from "@service/asyncStorage";
import { rejectErrorCodeHelper } from "@utils/rejectErrorMessageHelper";

function* fetchUser({ payload }) {
try {
@@ -50,8 +50,10 @@ function* logoutUser() {
console.log(error); // eslint-disable-line
} finally {
yield call(removeHeaderToken);
yield call(clearAll);
yield call(removeData, JWT_REFRESH_TOKEN)
yield call(removeData, JWT_TOKEN);
yield put(resetLoginState());
yield put(resetUserState());
}
}


Chargement…
Annuler
Enregistrer