How to Swizzle Document Datasource? #8028
-
|
I am trying to implement route protection, where some documents are public, and other documents are limited to specific users. I have implemented the sign in, and I am setting the scope of the document in its frontmatter: Then, I am wrapping each component that would render documents, to check if that user is logged in. However, rather than doing this for each component, is it possible to do this at the root? Or can I modify the dataset of docs before it goes out to be rendered, rather than intercepting it in the props? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
The root /layout doesn't currently have access frontmatter. Not all pages are Markdown documents with available frontMatter. You can try to swizzle
Not sure what your "wrapper protection" is exactly, but keep in mind that JS bundles containing potentially sensitive information are still available on Maybe you could also be interested in this upcoming "unlisted" feature? #8004 If you have doc 1 2 3, and if doc 2 is only available for logged-in users, maybe you'll want to make sure the doc navigation navigates from doc 1 to doc 3 instead of trying to navigate to the inaccessible doc2?
You can extend the docs plugin, modify created routes/props and whatever you want. However it might not be very easy. See also #4138 Related auth comment: #958 (comment) Note with Cloudflare workers and other edge functions, you can do some quite advanced things. For example, you could build 2 versions of your static website (one for anonymous, one for logged-in users). The edge fn can check auth and serve one or the other according to the auth status of the user. |
Beta Was this translation helpful? Give feedback.
The root /layout doesn't currently have access frontmatter. Not all pages are Markdown documents with available frontMatter.
You can try to swizzle
MDXContentand useuseFrontMatter(from https://github.com/roydukkey/docusaurus-theme-frontmatter, but we'll likely add something like this in core later)Not sure what your "wrapper protection" is exactly, but keep in mind tha…