Procházet zdrojové kódy

adding jwt token in local storage and redux store

feature/1371_homepage_and_navigation
Dzenis Hadzifejzovic před 3 roky
rodič
revize
4eab00ad80

+ 1
- 1
src/store/reducers/login/loginReducer.js Zobrazit soubor

function setUser(state, action) { function setUser(state, action) {
return { return {
...state, ...state,
user: action.payload,
token: action.payload,
}; };
} }



+ 4
- 4
src/store/saga/loginSaga.js Zobrazit soubor

function* fetchUser({ payload }) { function* fetchUser({ payload }) {
try { try {
const { data } = yield call(attemptLogin, payload); const { data } = yield call(attemptLogin, payload);
if (data.JwtToken) {
const user = jwt.decode(data.JwtToken);
yield call(authScopeSetHelper, JWT_TOKEN, data.JwtToken);
if (data.token) {
const user = jwt.decode(data.token);
yield call(authScopeSetHelper, JWT_TOKEN, data.token);
yield call(authScopeSetHelper, JWT_REFRESH_TOKEN, data.JwtRefreshToken); yield call(authScopeSetHelper, JWT_REFRESH_TOKEN, data.JwtRefreshToken);
yield call(authScopeSetHelper, REFRESH_TOKEN_CONST, data.RefreshToken); yield call(authScopeSetHelper, REFRESH_TOKEN_CONST, data.RefreshToken);
yield call(addHeaderToken, data.JwtToken);
yield call(addHeaderToken, data.token);
yield put(setUser(user)); yield put(setUser(user));
} }
yield put(fetchUserSuccess(data)); yield put(fetchUserSuccess(data));

Načítá se…
Zrušit
Uložit