next-password-protect
next-password-protect copied to clipboard
getInitialProps from _app are lost when using withPasswordProtect()
Describe the bug Any props set within custom _app component are lost when exporting withPasswordProtect()
To Reproduce Steps to reproduce the behaviour:
- Setup a custom _app file with getInitialProps setting a value.
- Export using withPasswordProtect()
- Login successfully
- Console log _app props on page and they're undefined
- Leave everything as is except remove withPasswordProtect() and your props will re-appear on the page
Expected behavior Props from _app shouldn't be overwritten or lost.
Stack Node fermium, Next 12, next-password-protect 1.7
+1
You should be able to attach getInitialProps to the instance returned from the HOC instead. See this modified example from the readme:
import { withPasswordProtect } from "next-password-protect";
// Before: export default App;
const ProtectedApp = process.env.PASSWORD_PROTECT
? withPasswordProtect(App, {
// Options go here (optional)
loginApiUrl: "/login",
})
: App;
// Set getInitialProps on HOC instance
ProtectedApp.getInitialProps = () => {
//
};
export default ProtectedApp;