Connect React App with DHIS2

Hi

I am trying to connect a new React App with DHIS2 instance but I am getting 401 Error Code.
http://localhost:3000 is already whitelisted.

Any help is much appreciated.
Thanks

1 Like

Hi @Sami,

Could you open the Network tab and check the response?

Thank you

2 Likes

Hi

here is the screenshot of Network Tab.

Thanks

1 Like

Hi! Unfortunately the play instances don’t allow for localhost to connect do to security settings. If possible I’d advise you to run your own instance locally using Docker

Instructions how to do so can be found here: Environment Setup | DHIS2 Developer Portal

2 Likes

Yes, It is working fine on when I connect it with local Instance. But when I connect it with any other Instance which is over https, then I encounter that error.

Actually I am want to connect it with a Instance which is on https.

Thanks

1 Like

Hi,

Have you added the CORS whitelist?

Thanks

2 Likes

Yes I http://localhost:3000 is already whitelisted in CORS.

Thanks

1 Like

Are you trying this with a self-hosted instance on https?

2 Likes

Hi, I think I’m having a similar issue. I got a new computer and had to setup the DHIS2 development environment from scratch. I created a new project with d2 app scripts and I’m not able to pass the login screen (see the image below). I did not add any code to the newly created project (it’s default code).
But when I run an old project that I have, it works perfectly fine. I was wondering if the there was an update on dhis2-cli or dhis2-ui that could be causing dhis. Best regards

2 Likes

Yes I am trying to connect with a self-hosted instance on https.

Hi @joao.machiana

Hope you are doing well.
what version of d2 are you using in your old application.

Hi Devs,

Was anyone successful with this. I get the same error, the user gets authenticated but the app thereafter calls the /api/system/info api which returns a 401 response. I have allowed cors from http://localhost:3000. I have attached a screenshot of my app. Any help will highly be appreciated.

1 Like

Hi
Sorry to see you’re facing this issue.

So if you go to the direct link of the server and use the username and password, you’d be able to login, right?

Would you share more about your setup? I’m guessing that the instance is running on Docker? What is the version of the DHIS2 instance you are using? Would you click on the ‘response’ tab in network to show what is the response to the /api/system/info GET request?