-
Notifications
You must be signed in to change notification settings - Fork 81
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
Documents aren't indexed when root is swizzled to add an authentication #119
Comments
As mentioned here https://docusaurus.io/docs/advanced/ssg#useisbrowser
Or you can also just use process env alone with optional chanining
|
Thanks for pointing out! Looks like this is a Docusaurus related issue rather than the plugin itself. Will update and close the issue after I can get auth working with this great plugin. |
Also, I was wondering is it possible to make auth work without conditionally rendering the root? Or the content must always be visible (returned) for the indexing to work? |
Indexing happens during build process, so yes you need to have some condition |
Hello, I've implemented an authentication that requires wrapping the root component with the authentication provider and checking access before displaying the content as shown below:
/src/theme/Root.tsx
/src/components/App.tsx
Basically, it will check if a user is authenticated before displaying the content, if not the user will be redirected to complete the sign-in first.
The authentication works fine but now the documents aren't being indexed.
docusaurus-lunr-search:: Start scanning documents in 8 threads docusaurus-lunr-search:: Indexing time: 1.594s docusaurus-lunr-search:: indexed 0 documents out of 95
After further investigation, I found that because in the
App.tsx
theisAuthenticated
will always befalse
during build and indexing which will result inchildren
not being returned and the page content cannot be indexed.Workaround
A workaround is to render the
children
during the build-time where the contents will be indexed. With the help ofisBrowser
andnpm_lifecycle_event
. I was able to make the indexing work while having the authentication check as in the code shown below:But this is a workaround and not a solution as I found that the
isBuildStage
istrue
when the page is first loaded and laterfalse
as intended. This makes the site's content briefly visible to the user before they are redirected. (I don't know whyisBrowser
isfalse
andprocess
is not undefined on the first load).Hope anyone can help me with this, thanks!
The text was updated successfully, but these errors were encountered: