FusionAuth
    • Home
    • Categories
    • Recent
    • Popular
    • Pricing
    • Contact us
    • Docs
    • Login

    Connection refused when I try to register a new user with @fusionauth/typescript-client

    Scheduled Pinned Locked Moved Solved
    Q&A
    2
    8
    2.9k
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • K
      kasir-barati
      last edited by

      Hi dear reader

      I am using Docker and terraform to configure my dev env in my PC and everything looks good, and by good I mean I can go to http:localhost:9011 and login as a super admin. My terrafrom also seems fine. But the issue is when I try to execute my integration test to verify that I can register a user. It fails with this error:

      {
        message: 'request to http://localhost:9011/api/user/registration/ failed, reason: connect ECONNREFUSED 127.0.0.1:9011',
        type: 'system',
        errno: 'ECONNREFUSED',
        code: 'ECONNREFUSED'
      }
      

      I am pretty sure that the configuration is working and I am passing the api key, tenant id, and host. So I am at a total lost and I hope you can help me to understand what is wrong. Meanwhile I'll try to fix it and if I managed to do it you can see it in my repo.

      Where I configured fusionauth SDK
      Where I am using SDK to register a new user
      Integration test suit

      Note: I checked the env variables and logged them in the console and everything seems to be fine as far as I could make sure.

      How to run the tests:

      1. Clone the repo
      2. cp .env.example .env
      3. npm ci
      4. npm i -G nx
      5. nx start:docker backend-e2e
      K 1 Reply Last reply Reply Quote 0
      • K
        kasir-barati @kasir-barati
        last edited by

        I guess I found out the issue, it was related to docker and networking, it seems that when I run the nodejs app on its own on my local env and just dockerize fusionauth and its stack it is working but now when I dockerize my nodejs app alongside the fusionauth. Any idea on what is wrong?

        K 1 Reply Last reply Reply Quote 0
        • K
          kasir-barati @kasir-barati
          last edited by

          I created a smaller and simpler version to reproduce this situation, you can find it here: https://github.com/kasir-barati/docker/tree/docker-compose/docker-compose-files/fusionauth-nodejs

          K 1 Reply Last reply Reply Quote 0
          • K
            kasir-barati @kasir-barati
            last edited by kasir-barati

            When I used @fusionauth/node-client SDK it thrown this error:

            {
              "statusCode": 500,
              "errorResponse": null,
              "successResponse": null,
              "exception": {
                "errno": -111,
                "code": "ECONNREFUSED",
                "syscall": "connect",
                "address": "127.0.0.1",
                "port": 9011
              }
            }
            

            I am pretty sure I am missing something here but dunno what is it 😅

            Any help?

            K 1 Reply Last reply Reply Quote 0
            • K
              kasir-barati @kasir-barati
              last edited by kasir-barati

              Now that I've followed the troubleshooting guideline I have realized that when I send a req directly to the fusionauth api via Curl it is working and it can create the user. So all is left is to dig in a little more and figure out what is wrong with the client libraries or to be more precise what I am doing wrong 😑

              Curl

              curl -X POST \
                http://localhost:9011/api/user/registration/ \
                -H 'X-FusionAuth-TenantId: 40b82d21-2343-40e3-bae0-20b63210bd96' \
                -H 'Authorization: 7ef6fa566cf6bd2948f86dc9174b1ad87a40a67fa00c72edab82d566b79eeb206d532b9f217eac391423d087c0a329bb5518d6281d2bb29c2919642b4cc7300f' \
                -H 'Content-Type: application/json' \
                -d '{
                "registration": {
                  "applicationId": "b94471aa-bc85-4538-b1a8-e3c4642c9c8b",
                  "data": {
                    "displayName": "Mohammad Jawad"
                  },
                  "username": "mohammad_jawad"
                },
                "sendSetPasswordEmail": true,
                "user": {
                  "email": "email@em.com",
                  "firstName": "kasir",
                  "lastName": "barati",
                  "username": "mohammad_jawad"
                }
              }'
              
              K 1 Reply Last reply Reply Quote 0
              • K
                kasir-barati @kasir-barati
                last edited by

                I guess I found out the issue, it was related to docker and networking, it seems that when I run the nodejs app on its own on my local env and just dockerize fusionauth and its stack it is working but now when I dockerize my nodejs app alongside the fusionauth. Any idea on what is wrong?

                K 1 Reply Last reply Reply Quote 0
                • K
                  kasir-barati @kasir-barati
                  last edited by

                  I had to access fusionauth instance with its service name and not localhost 😜. Just look at my .env.example to understand what was wrong.

                  mark.robustelliM 1 Reply Last reply Reply Quote 0
                  • K kasir-barati has marked this topic as solved on
                  • mark.robustelliM
                    mark.robustelli @kasir-barati
                    last edited by

                    @kasir-barati Thank you for sharing with the community!

                    1 Reply Last reply Reply Quote 0
                    • K
                      kasir-barati
                      last edited by

                      Hey folks,

                      Coming from the future. I just decided to change my docker-compose.yml to use network_mode: host therefore my former comment is no longer valid. Please look at my monorepo on how I am utilizing Terraform, Docker, mailcatcher as my local SMTP, NestJS, and NextJS.

                      I also wrote a couple of README.mds here and there for future references.

                      Feel free to give it a star on GitHub and or better yet use it.

                      1 Reply Last reply Reply Quote 0
                      • First post
                        Last post