I'm building a website with Docusaurus V2.
Since a Docusaurus website is fundamentally a React app, I wonder how we could add an authentication system to the website.
Is there any guide or sample where a Docusaurus website is linked to a database, a backend, or call APIs?
You could inject a script that initializes some form of authentication when the website first loads. Have a look at docusaurus-plugin-google-analytics, this is an example of injecting the GA script into a website.
To make database calls, you would need a server with a REST/GraphQL API. You can make calls from the UI using AJAX/fetch
.
To implement a very basic form of auth where you prevent unauthorized people from even accessing the website, you could implement auth at the web server level using Basic access auth.
Docusaurus websites are fundamentally for static documentation and they are best for building websites where everyone should see the same thing. If you want to selectively show content depending on the user, then maybe going with a server-side approach would be better.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With