text: import {
      LOGIN_SUCCESS,
      LOGIN_FAIL,
      LOAD_USER_SUCCESS,
      LOAD_USER_FAIL,
      AUTHENTICATED_SUCCESS,
      AUTHENTICATED_FAIL,
      PASSWORD_RESET_FAIL,
      PASSWORD_RESET_CONFIRM_SUCCESS,
      PASSWORD_RESET_CONFIRM_FAIL,
      PASSWORD_RESET_SUCCESS,
      SIGNUP_FAIL ,
      SIGNUP_SUCCESS,
      ACTIVATION_SUCCESS,
      ACTIVATION_FAIL,
      LOGOUT
     
  } from './types';
  import axios from 'axios';
  
  export const checkAuthenticated = () => async dispatch =>{
       if (localStorage.getItem('access')){
          const config  = {
              headers: {
                  'Content-Type': 'application/json',
                  'Accept': 'application/json'
              }
          };
  
          const body = JSON.stringify({token: localStorage.getItem('access')});
  
          try{
  
              const response = await axios.post(`${process.env.REACT_APP_API_URL}/auth/JWT/verify/`,body, config);
  
              if(response.data.code !== 'token_not_valid'){
                  dispatch({
                      type: AUTHENTICATED_SUCCESS
                  });
  
              }
              else{
                  dispatch({
                      type: AUTHENTICATED_FAIL
                  });
              }
  
  
          }catch(err){
              dispatch({
                  type: AUTHENTICATED_FAIL
              });
          }
       }
       else{
           dispatch({
               type: AUTHENTICATED_FAIL
           });
       }
  }
  
  export const load_user = (email, password) => async dispatch => {
  
      if (localStorage.getItem('access')){
          const config  = {
              headers: {
                  'Content-Type': 'application/json',
                  'Authorization': `JWT ${localStorage.getItem('access')}`,
                  'Accept': 'application/json'
      
      
              }
          };
  
          try{
              const response = await axios.get(`${process.env.REACT_APP_API_URL}/auth/users/me/`, config);
      
              dispatch({
                  type: LOAD_USER_SUCCESS,
                  payload: response.data
              });
      
          } catch(err){
      
              dispatch({
                  type: LOAD_USER_FAIL,
                  
              });
      
          }
      }
      
      else{
          dispatch({
              type: LOAD_USER_FAIL,
              
          });
      }
  
  };
  
  export const login  = (email, password) => async dispatch => {
      const config  = {
          headers: {
              'Content-Type': 'application/json'
  
  
          }
      };
      const body = JSON.stringify({email, password});
  
      try{
          const response = await axios.post(`${process.env.REACT_APP_API_URL}/auth/jwt/create/`, body, config);
  
          dispatch({
              type: LOGIN_SUCCESS,
              payload: response.data
          });
  
          dispatch(load_user());
  
      } catch(err){
  
          dispatch({
              type: LOGIN_FAIL,
              
          });
  
      }
  };
  
  export const signup  = (name,email, password, re_password) => async dispatch => {
      const config  = {
          headers: {
              'Content-Type': 'application/json'
  
  
          }
      };
      const body = JSON.stringify({name,email, password, re_password});
  
      try{
          const response = await axios.post(`${process.env.REACT_APP_API_URL}/auth/users/`, body, config);
  
          dispatch({
              type: SIGNUP_SUCCESS,
              payload: response.data
          });
  
          
  
      } catch(err){
  
          dispatch({
              type: SIGNUP_FAIL,
              
          });
  
      }
  };
  
  export const verify = (uid,token) => async dispatch =>{
      const config  = {
          headers: {
              'Content-Type': 'application/json'
  
  
          }
      };
      const body = JSON.stringify({uid, token});
  
      try{
          await axios.post(`${process.env.REACT_APP_API_URL}/auth/users/activation/`, body, config);
  
          dispatch({
              type: ACTIVATION_SUCCESS,
              
          });
  
          
  
      } catch(err){
  
          dispatch({
              type: ACTIVATION_FAIL,
              
          });
  
      }
  };
  
  
  export const reset_password = (email) => async dispatch =>{
      const config  = {
          headers: {
              'Content-Type': 'application/json'
  
  
          }
      };
      const body  = JSON.stringify({email});
  
      try{
          await axios.post(`${process.env.REACT_APP_API_URL}/auth/users/reset_password/`, body, config);
  
          dispatch({
              type: PASSWORD_RESET_SUCCESS
          });
  
      }catch(err){
  
          dispatch({
              type: PASSWORD_RESET_FAIL
  
          });
  
      }
  
  };
  
  export const reset_password_confirm = (uid, token,new_password,re_new_password) => async dispatch => {
      const config  = {
          headers: {
              'Content-Type': 'application/json'
  
  
          }
      };
      const body  = JSON.stringify({uid,token,new_password, re_new_password});
  
      try{
          await axios.post(`${process.env.REACT_APP_API_URL}/auth/users/reset_password_confirm/`, body, config);
  
          dispatch({
              type: PASSWORD_RESET_CONFIRM_SUCCESS
          });
  
      }catch(err){
  
          dispatch({
              type: PASSWORD_RESET_CONFIRM_FAIL
  
          });
  
      }
  
  
  
  };
  
  
  export const logout = () => dispatch => {
      dispatch({
          type: LOGOUT
      });
  }
  
  
  
  
  
  
  