我试图用身份验证处理函数包装getServersideProps,但一直收到这个错误:TypeError: getServerSideProps is not a function我的包装器看起来像这样:
export async function protect(gssp) {
return async (context) => {
const {req, res} = context;
const auth = await authHandler(req);
if (!auth.authenticated) {
res.statusCode = 302;
res.setHeader('Location', '/');
return;
}
context.auth = auth;
return await gssp(context);
}
}在页面上,getServerSideProps看起来像这样:
export const getServerSideProps = protect(async function(context) {
return {
props: {
auth: context.auth
}
}
})发布于 2021-01-15 07:52:39
调用protect(...)实际上返回一个promise,而不是一个函数,因为您显式地将它声明为async。要解决这个问题,您可以简单地从该函数中删除异步。
export function protect(gssp) {
// Remaining code untouched
}https://stackoverflow.com/questions/65476998
复制相似问题