auth.js 765 B

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