skip to Main Content

I am developing a multi-user application with a Flask back-end and react front-end. I had up till a day ago a working API for basic CRUD apps including authentication using JWT. Today, I was testing the application to ensure it worked and when I clicked the clicked generate account button on the website, I received a 403 Forbidden Error in console.

The Flask back-end console does not show messages, so I know that the request did not reach the back-end so therefore it is not a server side issue. This is the code from the front-end file called GenerateAccountModal.js

 function generateAccount(event) {
            var account = {
                username: username,
                password: password,
                dob: dob,
                city: city,
                sex: sex,
                firstname: firstName,
                lastname: lastName
            }

            const config = {
                method: 'post',
                url: '/generate',
                data: account,
                headers: {
                'Content-Type': 'multipart/form-data',
            }
        };

            function addMessage(result) {
                dispatch(messageAdded(result))
            }

            console.log(account)

            axios(config)
                .then((response) => {
                        let result = response.data.userMessage
                        addMessage(result)
                    },
                    (error) => {
                        addMessage(error.response.data.error)
                    });

        event.preventDefault()
        toggleClose()
    }

Again, I am quite confident there is nothing wrong with my code. I enabled cross origin resource on the back-end. Just one day ago, the code was working fine, and I do not have a reason to believe that it is not working today.

The only problem I can think occured was that early I connected to a VPN service and I actually ran my application using the VPN. As soon as I realized I was still on VPN, i disconnected but I have not been able to resolve the issue. The only exception to the problem is when i add localhost:5000 to the url. In this case, I obtain a different issue:
On the console it states, " Uncaught (in promise) TypeError: Cannot read properties of undefined (reading ‘data’)
at GenerateAccountModal.js:48:1"

The proxy is package-json is set to localhost:5000

So I am unsure what the issue is. I tried changing permission in the terminal to read and write to all parties. invalidated cache. I think my code is right but there might be a possibility i changed it slightly in the near past and now it doesnt work.

Please help with any advice.

Describes the situation about .

2

Answers


  1. Chosen as BEST ANSWER

    I have found the solution to this problem. There was actually 2 problems here. The first is that Airtunes on my Macbook Air was enabled on Port 5000. This made it so that the server I was targetting was completely wrong and it was returning 403. The solution is to go to system preferences, sharing, and then disable Airtunes, or Airplay.

    Secondly, the proxy was stored in cached as the same port number as front end client. So what you want to do is delete package-lock-json, then in your IDE invalidate cache and restart, or just restart. Run npm start, even without re installing package lock json. I'll have to continue working through my project to see if I need to reinstall that at some point.

    I was right about not having anything wrong with my code afterall.


  2. It seems like your issue is related to one of the parameters being sent to the server. The error message displayed in the browser console states that there is an error at line 48 of the GenerateAccountModal.js file, indicating an issue with the ‘data’ variable from the server response. This might imply that the response received from the server does not contain a ‘data’ parameter, leading to an undefined error, particularly when using localhost:5000.

    Since your problem doesn’t seem to be with connecting to a remote server, but rather with sending requests to the server, you can try the following steps to troubleshoot:

    1. Check Sent Variables: Ensure that all required values for creating a user account, such as ‘username’, ‘password’, and others, are properly initialized and none of them are undefined.

    2. Inspect Server Response: Make sure that the server is responding correctly and that the response includes the ‘data’ field. The response you receive might have an unexpected format, causing this error.

    3. Review Proxy Settings: If you’re using a proxy, ensure that the proxy settings are configured correctly and that the requests are being sent to the server through the correct path.

    4. Utilize Development Tools: Use development tools like DevTools in your browser to inspect the requests sent and received, as well as server responses, to better analyze the issue.

    5. Check CORS Settings: Make sure that CORS settings are properly configured to allow access to server resources from different origins.

    By following these steps, you might be able to resolve your issue. If you continue to face problems, please provide further information so that we can assist you better.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search