import {Provider, connect} from 'react-redux';
import {createStore, combineReducers, applyMiddleware, bindActionCreators} from 'redux';
import thunk from 'redux-thunk';
import {actionPromise, actionAuthLogout, actionAuthLogin, gql, actionUserFindOne} from "./index"
import { useEffect } from 'react';



const actionLogin = (login, password) => 

 async dispatch => {

    const res = gql(
        `query login($login:String, $password:String){
          login(login:$login,password:$password)
        }`, { login, password } );

    // let loginData = await dispatch(actionPromise('login', res))


    let loginData = await dispatch(actionPromise('login', res))



    if (loginData && loginData.data && loginData.data.login){

         dispatch(actionAuthLogin(loginData.data.login));
         //dispatch(actionUserFindOne(loginData.data.login.sub._id))

    }
}

export default actionLogin;