auth.js 708 B

123456789101112131415161718192021222324252627282930
  1. import { AUTH_USER, AUTH_RENEW, UNAUTH_USER, SENT_VERIFICATION } from '../actions/actionTypes';
  2. const initialState = {
  3. isAuthenticated: false,
  4. sentVerification: false,
  5. user: '',
  6. renew: false,
  7. };
  8. const auth = (state = initialState, action) => {
  9. switch (action.type) {
  10. case AUTH_USER:
  11. return {
  12. ...state,
  13. isAuthenticated: true,
  14. user: action.payload,
  15. sentVerification: false,
  16. };
  17. case AUTH_RENEW:
  18. return { ...state, renew: true };
  19. case UNAUTH_USER:
  20. return initialState;
  21. case SENT_VERIFICATION:
  22. return { ...state, sentVerification: true, user: action.payload };
  23. default:
  24. return state;
  25. }
  26. };
  27. export default auth;