When attempting to implement an auth handler function around getServersideProps
, I encountered the following error message:
TypeError: getServerSideProps is not a function
The wrapper code in question is as follows:
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);
}
}
The implementation of getServerSideProps on the page appears like this:
export const getServerSideProps = protect(async function(context) {
return {
props: {
auth: context.auth
}
}
})