【问题标题】:nextjs console.log doesn't work inside function return functionnextjs console.log 在函数返回函数中不起作用
【发布时间】:2020-05-31 11:35:49
【问题描述】:

我在玩 nextjs 我很难调试一个像 这个:

export const authInitialProps = isProtectedRoute => {
  console.log("mylog");// this works 
  return ({ req, res }) => {
    console.log("inner my log", req); // this doesn't work
  };
};

在页面中使用

ProfilePage.getInitialProps = async () => {
  const auth = authInitialProps(true);
  if (!typeof auth === "function") {
    const user = await getUserProfile();
    return { user };
  }
  return { user: null };
};

我从来没有在 chrome 控制台中看到“inner my log” 在我的控制台终端中。 请问有什么问题?

【问题讨论】:

    标签: next.js


    【解决方案1】:

    试试这个可能有用:

    ProfilePage.getInitialProps = async () => {
      const auth = await authInitialProps(true); // await added
      if (!typeof auth === "function") {
        const user = await getUserProfile();
        return { user };
      }
      return { user: null };
    };
    

    我认为它应该是异步的而不是通过它!

    【讨论】:

      猜你喜欢
      • 2017-06-15
      • 2016-08-05
      • 2015-05-31
      • 1970-01-01
      • 1970-01-01
      • 2010-12-16
      • 1970-01-01
      • 1970-01-01
      • 2012-10-23
      相关资源
      最近更新 更多