text: // constants
  const SET_USER = "session/SET_USER";
  const REMOVE_USER = "session/REMOVE_USER";
  
  const setUser = (user) => ({
      type: SET_USER,
      payload: user
  })
  
  const removeUser = () => ({
      type: REMOVE_USER
  })
  
  
  
  // thunks
  export const authenticate = () => async (dispatch) => {
      const response = await fetch('/api/auth/', {
          headers: {
              'Content-Type': 'application/json'
          }
      });
  
      const data = await response.json();
      if (data.errors) {
          return;
      }
      dispatch(setUser(data))
      
  }
  
  export const login = (email, password) => async (dispatch) => {
      const response = await fetch('/api/auth/login', {
          method: 'POST',
          headers: {
              'Content-Type': 'application/json'
          },
          body: JSON.stringify({
              email,
              password
          })
      });
      const data = await response.json();
      if (data.errors) {
          return data;
      }
      dispatch(setUser(data));
      return {};
  }
  
  export const logout = () => async (dispatch) => {
      const response = await fetch("/api/auth/logout", {
          headers: {
              "Content-Type": "application/json",
          }
      });
      const data = await response.json();
      dispatch(removeUser());
  };
  
  
  export const signUp = (firstname, lastname, username, email, user_avatar, password) => async (dispatch)=> {
      const response = await fetch("/api/auth/signup", {
          method: "POST",
          headers: {
              "Content-Type": "application/json",
          },
          body: JSON.stringify({
              firstname,
              lastname,
              username,
              email,
              user_avatar,
              password,
          }),
      });
      const data = await response.json();
      dispatch(setUser(data));
  }
  
  // reducer
  
  const initialState = { user: null };
  
  // useSelector(state => state.session.user)
  
  export default function reducer(state = initialState, action) {
      switch (action.type) {
          case SET_USER:
              return { user: action.payload };
          case REMOVE_USER:
              return { user: null };
          default:
              return state;
      }
  }
  