Files
codecrumbs/example-project/src-client/auth/reducer.js
2019-01-26 17:19:19 +01:00

27 lines
585 B
JavaScript

import { Record } from 'immutable';
import { INIT_AUTH, SIGN_IN_SUCCESS, SIGN_OUT_SUCCESS } from './action-types';
export const AuthState = new Record({
authenticated: false,
id: null
});
export function authReducer(state = new AuthState(), {payload, type}) {
switch (type) {
case INIT_AUTH:
case SIGN_IN_SUCCESS:
return state.merge({
authenticated: !!payload, // cc:signin#2;toggle 'authenticated' flag
id: payload ? payload.uid : null
});
case SIGN_OUT_SUCCESS:
return new AuthState();
default:
return state;
}
}