28 lines
895 B
TypeScript
28 lines
895 B
TypeScript
import { fetchLogin, fetchRefresh } from "../../services/auth";
|
|
import { AuthActionTypes, AuthAction } from "./actions";
|
|
import { IAuthState } from "./types";
|
|
|
|
function authReducer(state: IAuthState, action: AuthAction): IAuthState {
|
|
switch (action.type) {
|
|
case AuthActionTypes.FETCH_LOGIN_START:
|
|
fetchLogin(action.payload.username, action.payload.password);
|
|
return state;
|
|
case AuthActionTypes.FETCH_LOGIN_FINISH:
|
|
return {
|
|
...state,
|
|
session: action.payload,
|
|
};
|
|
case AuthActionTypes.FETCH_REFRESH_START:
|
|
fetchRefresh();
|
|
return state;
|
|
case AuthActionTypes.FETCH_REFRESH_FINISH:
|
|
return {
|
|
...state,
|
|
session: action.payload,
|
|
};
|
|
default:
|
|
return state;
|
|
}
|
|
}
|
|
|
|
export { authReducer };
|