如何对Mercadolivre请求进行隐形回调



i m use the mercadolivre s api,并且需要一个请求,该请求将带有令牌但...我需要这个过程是看不见的,只返回一个令牌。

我用后端调用该功能,回调为:

import React, { Component } from 'react';
import {getToken} from '../../../auth';
import axios from 'axios';
import Swal from 'sweetalert2';
class CallBack extends Component {
  constructor(props) {
    super(props);
    const token = window.location.href.split('?')[1].split('=')[1].split('&')[0];
    this.state = {
      token: token,
      message: '',
      status: '',
      executed: false,
      doIt: 0
    };
  }
  render(){
    const token = this.state.token;
    return (
        !this.state.executed ? (
            axios.post(process.env.REACT_APP_API_URL + `/accounts/from-mercado-livre`,
                {"code": token,},
                {headers: {"Authorization": 'Bearer ' + getToken()}},
            ).then(res => {
              this.setState(
                  {
                    executed: true,
                    doIt: 2
                  }
              )
              if (res.data.status === 'success') {
                Swal.fire({
                  html: '<p>' + res.data.message + '</p>', type: 'success', showConfirmButton: true,
                  onClose: () => {
                    this.props.history.push('/listacontas');
                    window.location.reload();
                  }
                });
              } else {
                Swal.fire({
                  html: '<p>' + res.data.message + '</p>', type: 'error', showConfirmButton: true,
                  onClose: () => {
                    this.props.history.push('/listacontas');
                    window.location.reload();
                  }
                });
              }
            }).catch(error => {
              console.log('rejected');
              console.log(error.response);

              if (error.response !== undefined) {
                Swal.fire({
                  html: '<p>' + error.response.data.message + '</p>',
                  type: 'error',
                  showConfirmButton: false,
                  showCancelButton: true,
                  cancelButtonText: 'Fechar',
                  onClose: () => {
                    this.props.history.push('/listacontas');
                    window.location.reload();
                  }
                });
              } else {
                this.props.history.push('/listacontas');
                window.location.reload();
              }
            })
        ) : (
            console.log('None')
        )
    ) 
  }
}
export default CallBack;

我将用户令牌发送给我的后端及其返回其他令牌,并带有用于回调的信息。

我希望使用户不可见,只显示成功消息。

这是不可能的,因为事件在浏览器之外开始。

我做了一种异步方法,该方法使用后端接收状态并解决问题。但是,我无法在这里共享它,因为它包含私人信息。

最新更新