Docusaurus: Router interceptor and Authentication

Created on 30 May 2020  路  6Comments  路  Source: facebook/docusaurus

Hey I'm a complete newbie in docusaurus and I am loving it <3

We have a private document that we want to publish it and make it accessible to our members but we need some sort of authentication even the most simple one with a hard coded username and password...

I made a simple front-end login page and I managed to get it working only for FIRST page which is the main one in the classic theme.

Seems like when user goes to directly to one of the doc page route bypasses the main page...

I was wondering if there is any API to intercept and play around with the router by using the classic theme itself. I do not want to eject or extract the theme itself and go into rabbit whole of how classic theme made and etc.

image

needs triage questions

All 6 comments

I think you may have better luck with looking into actual deployment platform. Otherwise, you're changing the internal behaviour of Docusaurus linking. That can make it difficult to upgrade your instance of Docusaurus, unless there's a way to do it properly.

I deployed my site in AWS (S3 + CloudFront). Plus WAF service linked to the CloudFront made it possible so that the site is only available from certain IP addresses. You can also integrate single sign on services with CloudFront. It all depends on how and where you're deploying the site.

Hope that helps.

@amimas I agree with you, it can be achieved if the deployment platform has a way to shield it.

We were thinking of using Netlify... (I believe a lot of people deploy their docs in Netlify as well) I am not sure if we will be able to shield it through Netlify...

you're changing the internal behaviour of Docusaurus linking. That can make it difficult to upgrade your instance of Docusaurus, unless there's a way to do it properly.

What you mentioned above is exactly why I didn't want to modify Docusaurus linking capability and how it's tied to the rest of the code...

Just to confirm, based on what you mentioned currently, there is no such a way to achieve this smoothly through Docusaurus right?

Yes, that is right, there is no way to implement authentication in Docusaurus, for example, this can be done using a proxy server (see https://github.com/facebook/docusaurus/issues/2769 for more details).

@lex111 Thanks for the issue - I am sure that will help a lot.

How about intercepting the router and playing around with it.... There wasn't much of a documentation around that as well.

Do you think exposing some routing API would be an issue?

We are using a react-router and as far as I know there is no route guard, so the only and best option is using a proxy server or similar feature provided by your hosting provider.

@lex111 sweet as - on that note, I will close this issue thanks

Was this page helpful?
0 / 5 - 0 ratings