next.js - nextjs console.log 在函数返回函数中不起作用
问题描述
我正在玩 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 控制台和我的控制台终端中看到“我的日志内部”。请问有什么问题吗?
解决方案
试试这个它可能工作:
ProfilePage.getInitialProps = async () => {
const auth = await authInitialProps(true); // await added
if (!typeof auth === "function") {
const user = await getUserProfile();
return { user };
}
return { user: null };
};
我认为不通过它应该是异步的!
推荐阅读
- css - 如何使用关键帧在鼠标移出时实现反向动画
- android - 如何修复我的飞镖开发工具?(颤振 Android 许可证 - 错误 65)
- sql - 如何从您的子查询表中打印两个属性值
- java - 如何从文件路径中获取文件 Uri?(范围存储)
- excel - 如何在excel中获取所选范围内每个单元格的地址
- airflow - 使用“su”作为另一个用户运行 Airflow DAG
- flutter - 防止为 FutureBuilder 中的特定 ListItem 更改重建 ListView.Builder
- json - 数据解析的单个元素导致代码无法工作
- arrays - 动态数组是否在应用程序关闭时自动释放?
- reactjs - 反应编程总是得到一个'未处理的拒绝(TypeError):setToken不是一个函数'