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

Can't parse document when auth is added in Root.js #187

Open
biboc opened this issue Jun 20, 2023 · 5 comments
Open

Can't parse document when auth is added in Root.js #187

biboc opened this issue Jun 20, 2023 · 5 comments

Comments

@biboc
Copy link

biboc commented Jun 20, 2023

If I add an auth in src/theme/Root.js, search-local can't parse meta data:

[ERROR] Error: The `docusaurus_tag` meta tag could not be found. Please make sure that your page is wrapped in the `<Layout>` component (from `@theme/Layout`). If it is, then this is a bug, please report it.

src/theme/Root.js:

export default function Root({children}) {
  const [isConnected, setIsConnected] = useState(false); // Manage authentification

  return <>{
    isConnected ? (
      <>{children}</>
    ) : (
      <div className="login">
        <div className="login__container">
          <button className="login__btn" onClick={() => setIsConnected(true)}>
            Login
          </button>
        </div>
      </div>
    )
  }</>;
}

Could I first build the index in dev env without authentification and then build in prod and use the index generated previously?
Thanks,

@lucasalberto01
Copy link

+1

@rivenlogik
Copy link

rivenlogik commented Aug 15, 2023

+1 running into this as well (trying to swizzle Root) to add authentication layer.

@anthony-df-nguyen
Copy link

anthony-df-nguyen commented Oct 12, 2023

I ran into this issue as well, what ended up working for me was swizzling the Layout component and putting my authentication logic within the <LayoutProvider>

@rivenlogik
Copy link

I ended up going with a different Docusaurus plugin, which still had a similar issue (it wouldn't index anything but ran fine). So I essentially created a check within the Root component that looked for an environment variable to be set to disable auth that I utilized during build to index .. copied/pasted index files out .. rebuild with authentication and copy index files back in.

It's not great, but it worked :) in case anyone else was considering this approach. Be sure to consider the risks involved if you accidentally break authentication of your site during deploy. Sounds like the option above is a better idea. I might migrate to it to avoid the workaround I built.

@biboc
Copy link
Author

biboc commented Oct 13, 2023

I ran into this issue as well, what ended up working for me was swizzling the Layout component and putting my authentication logic within the <LayoutProvider>

Thanks for your answer
Can you share your code?

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

4 participants