[Question] How can I secure private pages, server side / ssr? #3480
Replies: 3 comments
-
Custom sources are called at build-time, downloaded, and a database dump of the details is generated. Nuxt is built, which generates the client and the server. Nuxt content generates all of its pages, dumps, etc, at build time, including custom sources. When a user requests data from a specific collection, nuxt content will download a In other words, those are still available in the client. You can have a look at the When the user wants a specific database, they hit the Line 152 in a9fed2f nuxt.options.routeRules![`/__nuxt_content/**`] = { robots: false }
manifest.collections.forEach((collection) => {
if (!collection.private) {
nuxt.options.routeRules![`/__nuxt_content/${collection.name}/sql_dump.txt`] = { prerender: true }
}
}) You can create server middleware to dictate if the user can download the dump, perhaps? Alternatively you could solve this through an external application like traefik and a reverse proxy with forward auth. Something like Authentik works completely out of the box and lets you secure content on the proxy level. You could also block the client from accessing a particular dump, but allow the server to access it, and then access your content via an api endpoint and useFetch, with some authentication middleware. You would lose access to a lot of the client side features that come with nuxt content, but could still use markdown and whatnot for your content. |
Beta Was this translation helpful? Give feedback.
-
Hi @codebykyle Thanks for the detailed info! There was a time where I would definitely pursue the reverse proxy path, Authentik, Authelia, etc. I'm now old 😄 I like simple solutions, easily replicable. Would it be impossible to just not build anything before hand? Having the files, but No collection configured in the Content. I'm assuming we would loose the search feature in the body contents. That could be thought later, maybe just by indexing only titles. Is this very hard to achieve? |
Beta Was this translation helpful? Give feedback.
-
I've been thinking about this problem as well for some time, as I also have some pages I'd like to move behind an authentication wall. Something that has come up, that might actually be somewhat related to this, is that with really large collections of markdown-content, the databases get huge. Which means when the client access content related to these pages, this huge collection dump is downloaded to the client, even though they might only ever access 2 pages of it. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Hello everyone.
To handle private pages, I would expect the content to be only available server side, behind authentication (I'll be using Laravel Sanctum).
As per the reading, discussion, issues etc, I understand all the nuxt/content is not server side, am I right?
To do that, should I use Custom sources?
https://content.nuxt.com/docs/advanced/custom-source
Would I have to render the the thing in SSR, or provide the file contents in a JSON?
Or is there already a way I just wasn't able to find it?
Beta Was this translation helpful? Give feedback.
All reactions