when I start the Django server in the Project IDX editor using the command python3 manage.py runserver, the server starts successfully. However, when I send a POST request to this API, I receive the following error:
Access to XMLHttpRequest at 'https://ssh.cloud.google.com/devshell/gateway/oauth?_workstationRedirectOrigin=https%3A%2F%2F3000-idx-saghfinoo-1719090394822.cluster-qtqwjj3wgzff6uxtk26wj7fzq6.cloudworkstations.dev&state=' (redirected from 'https://8000-idx-saghfinoo-1719090394822.cluster-qtqwjj3wgzff6uxtk26wj7fzq6.cloudworkstations.dev/api/v1/users/verify-number') from origin 'https://3000-idx-saghfinoo-1719090394822.cluster-qtqwjj3wgzff6uxtk26wj7fzq6.cloudworkstations.dev' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource.
How do I solve this problem?
1 Like
Basically you need to authenticate your frontend request with the backend server, so you can do this by setting the authenticate flag to true in the post request…
For more info checkout this blog post: Full-stack development in Project IDX
I also tried this method but the CORS error still exists. I even generated a temporary token using the ‘Generate access token’ option and placed it in the POST request as follows:
"Authorization": "Bearer eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJodHRwczovL2Nsb3VkLmdvb2dsZS5jb20vd29ya3N0YXRpb25zIiwiYXVkIjoiaWR4LXNhZ2hmaW5vby0xNzE5MDkwMzk0ODIyLmNsdXN0ZXItcXRxd2pqM3dnemZmNnV4dGsyNndqN2Z6cTYuY2xvdWR3b3Jrc3RhdGlvbnMuZGV2IiwiaWF0IjoxNzIwMTI5NDU3LCJleHAiOjE3MjAxMzMwNTd9.ZAd8EfVT_FPh3hwRTEhe--vTxPykO02bo3yyharPEADsIq3VFPov_wa6ov_lWTAVBXBILtGiB9wV9B7UXDQm4_3lVROM2v-c0Gi1sa2r9x3YXapN7hpOVuDjXCEQTr3Tei6ggLTRs0F37BJXDC4HI5GBnaOxM3ogCaOvfIrNDctmkMnovfLEj-4Z1kuI9f6Pz6jUkfu0wCkHDFIaPUxLQels7aKiVKAPRVsGJbsmal2hM7RcEa7nzQRZJhF7VcH6gR2dfl-1E5UoxgVHBDYK7XjRYZhKDK_7Ni4CAxlzR-J1b0Qo2h_AhwXzlZqzbVqmt8WOYwU-25PhC0ugf9Kl6g"
But this time I got the error:
{detail: 'Given token not valid for any token type', code: 'token_not_valid', messages: Array(1), status: 401}