alert-author-32387
10/12/2024, 12:03 AM# In browser
Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at <http://localhost:4000/sessions/whoami>. (Reason: CORS request did not succeed). Status code: (null).
# In my console
➜ junta-interfaz git:(main) ✗ npx @ory/cli tunnel --dev <http://localhost:3000> --port 4000 --allowed-cors-origins "*" --debug
A browser should have opened for you to complete your login to Ory Network.
If no browser opened, visit the below page to continue:
<https://project.console.ory.sh/oauth2/auth?audience=https%3A%2F%2Fapi.console.ory.sh&client_id=ory-cli&code_challenge=tl9t-5S9BvTjYNctOUSiGpDm9h6QAo99ec55wqF7Q7E&code_challenge_method=S256&prompt=login+consent&redirect_uri=http%3A%2F%2F127.0.0.1%3A63683%2Fcallback&response_type=code&scope=offline_access+email+profile&state=nTIT60NzhLKVS4DLnblxsz1MKRqb3Otv>
# In another console
➜ junta-interfaz git:(main) ✗ npm run dev
> junta-interfaz@0.1.0 dev
> next dev
▲ Next.js 14.2.15
- Local: <http://localhost:3000>
- Environments: .env
✓ Starting...
✓ Ready in 1096msbrief-egg-61061
10/12/2024, 12:04 AMbrief-egg-61061
10/12/2024, 12:04 AMlocalhost or 127.0.0.1, but not both[^1^][^2^]. Using both interchangeably in your code can cause problems with the origin of HTTP cookies sent by the application[^1^][^2^]. To get your application that runs locally and Ory APIs on the same domain, you can use Ory Tunnel, a development tool bundled with Ory CLI[^1^][^2^]. You can start the Ory Tunnel with the following command: bash npx @ory/cli tunnel --dev <http://localhost:3000> After running this command, Ory APIs will be mirrored on `http://localhost:4000`[^1^][^2^]. You should use this URL as the baseUrl for the @ory/client SDK[^1^][^2^]. The --dev flag disables security checks for easier integration and should not be used when deploying the Tunnel to a staging environment[^1^][^2^]. If you're still encountering CORS errors after following these steps, you can use the --allowed-cors-origins flag with the Ory Tunnel command to specify a list of allowed CORS origins[^8^]. However, Ory Network doesn't allow setting the CORS origins to be *, null or `localhost/127.0.0.1`[^6^]. For local development with localhost/127.0.0.1, it's recommended to use Ory Tunnel[^6^]. [^1^]: (source: https://www.ory.sh/docs/getting-started/integrate-auth/react#run-ory-apis-on-localhost) [^2^]: (source: https://www.ory.sh/docs/getting-started/local-development#local-development) [^6^]: (source: https://www.ory.sh/docs/guides/cors) [^8^]: (source: https://www.ory.sh/docs/cli/ory-tunnel#options)alert-author-32387
10/12/2024, 12:05 AMbrief-egg-61061
10/12/2024, 12:05 AMbrief-egg-61061
10/12/2024, 12:05 AM--port flag[^8^]. However, the --port flag is not mentioned in the official Ory documentation, so it's possible that it might not be supported. If specifying the port doesn't work, you could try running the tunnel without the --port flag, as the Ory APIs should be automatically mirrored on `http://localhost:4000`[^1^][^2^]. 2. Check the baseUrl in your application: The baseUrl for the @ory/client SDK in your application should be set to <http://localhost:4000>, which is where the Ory APIs are mirrored[^1^][^2^]. 3. Ensure the --dev flag is used for local development: The --dev flag disables security checks for easier integration and should be used when developing locally[^1^][^2^]. However, it should not be used when deploying the Tunnel to a staging environment[^1^][^2^]. 4. Check the allowed CORS origins: If you're still encountering CORS errors, you can use the --allowed-cors-origins flag with the Ory Tunnel command to specify a list of allowed CORS origins[^8^]. However, Ory Network doesn't allow setting the CORS origins to be *, null or `localhost/127.0.0.1`[^6^]. If you've checked all of these things and you're still encountering issues, it might be helpful to look at the debug output from the Ory Tunnel. You can enable debug output by using the --debug flag when starting the tunnel[^8^]. [^1^]: (source: https://www.ory.sh/docs/getting-started/integrate-auth/react#run-ory-apis-on-localhost) [^2^]: (source: https://www.ory.sh/docs/getting-started/local-development#local-development) [^6^]: (source: https://www.ory.sh/docs/guides/cors) [^8^]: (source: https://www.ory.sh/docs/cli/ory-tunnel#options)