Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can we link a Docusaurus website to a database?

Tags:

docusaurus

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?

like image 871
SoftTimur Avatar asked Aug 20 '19 22:08

SoftTimur


1 Answers

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.

like image 124
Yangshun Tay Avatar answered Sep 22 '22 07:09

Yangshun Tay