Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

getInitialProps from _app are lost when using withPasswordProtect() #59

Open
specialfae opened this issue Jun 29, 2022 · 2 comments
Open

Comments

@specialfae
Copy link

specialfae commented Jun 29, 2022

Describe the bug
Any props set within custom _app component are lost when exporting withPasswordProtect()

To Reproduce
Steps to reproduce the behaviour:

  1. Setup a custom _app file with getInitialProps setting a value.
  2. Export using withPasswordProtect()
  3. Login successfully
  4. Console log _app props on page and they're undefined
  5. 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

@vildantursic
Copy link

+1

jaiew added a commit to jaiew/next-password-protect that referenced this issue Jan 9, 2023
jaiew added a commit to jaiew/next-password-protect that referenced this issue Jan 9, 2023
jaiew added a commit to jaiew/next-password-protect that referenced this issue Jan 9, 2023
@vf-telwing
Copy link

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;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants