import { actionPromise } from ".";
import gql from "../api";

const actionLogin = (login, password) =>
  actionPromise('login', gql(`query authorize ($login:String, $password:String){
    login(login:$login, password:$password)}`
  , 
    {
      "login": `${login}`,
      "password":`${password}`
    }
  )
)

const actionAuthLogin  = token => ({type: 'AUTH_LOGIN', token})

const actionFullLogin = (login, password) =>
  async dispatch => {
    let token = await dispatch(actionLogin(login, password)); 

    if (token){
        dispatch(actionAuthLogin(token))
    }
  }

export default actionFullLogin;  