Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ssl/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 链路内部的等待功能_Javascript_Reactjs_Apollo - Fatal编程技术网

Javascript 链路内部的等待功能

Javascript 链路内部的等待功能,javascript,reactjs,apollo,Javascript,Reactjs,Apollo,我每次执行apollo API调用时都会运行这部分代码。我的目标是在进行API调用之前检查用户是否经过身份验证,是否具有最新刷新的令牌。我的问题是,我无法等待注释掉的行,因为函数不是异步的 const authenticationLink = new ApolloLink((operation, forward) => { // const currentSession = await Auth.currentSession(); // setAccessToken(curren

我每次执行apollo API调用时都会运行这部分代码。我的目标是在进行API调用之前检查用户是否经过身份验证,是否具有最新刷新的令牌。我的问题是,我无法等待注释掉的行,因为函数不是异步的

const authenticationLink = new ApolloLink((operation, forward) => {

  // const currentSession = await Auth.currentSession();
  // setAccessToken(currentSession.signInUserSession.idToken.jwtToken)

  if (typeof token === "string") {
    operation.setContext(() => ({
      headers: {
        Authorization: token
      }
    }));
  }

  return forward(operation);
});


const standardLink = ApolloLink.from([
  authenticationLink,
  httpLink
]);
如果我将authenticationLink设置为异步,我是否需要更改下面的其他代码以等待它,或者它是否可以保持不变?

等待与异步一起使用。(

替换

const authenticationLink = new ApolloLink((operation, forward) => {


不幸的是,这导致了代码中的错误。网络错误:inner.subscribe不是一个函数请查看那些Github答案>
const authenticationLink = new ApolloLink(async (operation, forward) => {