import { Auth } from '@domain'; // import * as actions from 'app/actions/auth.action'; import * as actions from '@actions/auth.action'; const initialState: Auth = {}; export function reducer(state = initialState, action: actions.AuthActions ): Auth { switch (action.type) { case actions.AuthActionTypes.LoginSuccess: case actions.AuthActionTypes.RegisterSuccess: { // return { action.payload }; // 注册时还没有用户id const auth = action.payload as Auth; return { token: auth.token, userId: auth.user ? auth.user.id : undefined }; } case actions.AuthActionTypes.LoginFail: case actions.AuthActionTypes.RegisterFail: { // payload will be object. // console.log('auth redu: ' + action.type, action.payload); return { err: action.payload as string}; } default: { return state; } } }