CORS error with netlify identity

I copied and pasted the react netlify example from the docs, and when I try and paste my url in, it says "Failed to load settings from "

Console error:
Access to fetch at 'https://<my-site>.netlify.app/.netlify/identity/settings' from origin 'http://localhost:3000' 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. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled.

Iā€™ve noticed a number of people mentioning netlify-cms, I donā€™t even know what that is. Also not using a git-gateway.

I have no idea why itā€™d be doing this, itā€™s worked for another react project in the past.

Youā€™re getting that error because your local server has a domain of ā€˜localhostā€™, which doesnā€™t match .netlify.app. Have you tried deploying your code and see if you still get that error?

It is actually a bug on Netlify CMS end.

Try using localhost:8888 and it will work. In my case, /.netlify/git/settings was only allowing http://localhost:8888 while /.netlify/identity/settings was allowing any host * (so one of the two worked with port 3000 as well).

LE: it actually appears when the API call times out. Couldnā€™t fix it with re-linking Git Gateway, yet. (when trying to access it directly at myappname.netlify.app/admin). For my other apps, it works fine.

LLE: works now (regardless of localhost and port number), took some time, uninstall/reinstalled Netlify Github App, relinked the repo, re-enabled the Identity Git Gateway.

Thanks @jozsi for reporting the issue and the solution. When working with the CMS locally with identity and git gateway, it should ask for your site URL and store it in local storage, so it knows how to connect to those services. When working with the live site it just uses the current domain. Iā€™ve seen recent cases where it takes some time for git gateway to initialize, but it didnā€™t result in CORS errors so thank you for informing us. Regardless both git gateway and identity should allow any host (either by mirroring the origin or by sending a *)

1 Like

Dear @erez, itā€™s a pleasure to observe the development of the CMS on GitHub.

Iā€™ve had the site URL set. So basically when the Git gateway was timing out (it was not yet initialized; didnā€™t get any response for minutes, unlike the Timeout error that happens in some scenaries like when a token re-issue is requested), the CORS prelight request responded instantly without the allowance of * hosts. Unfortunately I didnā€™t save the response headers and canā€™t reproduce anymore.

1 Like

That sounds unusual @jozsi. Glad things are working for you now. If you follow @erezā€™s steps, things should work without issue. If you are able to reproduce the issue again, please do let us know.

1 Like

@JamesWholebear it look like the guys didnā€™t reply to you and moved the conversation away. Did you solved the issue ? You will make me so happy if you share the how to.

Thanks.

Iā€™ve tried the above steps numerous times and the issue still persists with the same error.

Are there any other ways to further diagnose the issue? @jjalonso @Dennis

To not stop development. Iā€™m just using a chrome extension to allow cors.

It sounds like running on port 8888 mightā€™ve been the solution? (This is implying using netlify dev, the CLI command for running and serving your SSG, which defaults to using port 8888)

Yea, for the original poster, it does look like the solution was to use port 8888. There was no confirmation from the poster but I assume that since they didnā€™t come back that it did work. :slight_smile:

Iā€™m using Port 8888 and itā€™s throwing me a page not found error.

Iā€™ve tried using chrome extensions, relinking repo, relinking Netlify app on Github, relinking Netlify Auth. Nothing is working for me, and the same error persists:

ā€œAccess to fetch at ā€˜https://{URL}/.netlify/identity/settingsā€™ from origin ā€˜http://localhost:8000ā€™ has been blocked by CORS policy: Response to preflight request doesnā€™t pass access control check: Redirect is not allowed for a preflight request.ā€

The strange thing is when I deploy the site, I can access the CMS there. I want to be able to quickly be able to update the CMS without having to deploy to Netlify each time.

Would really appreciate some guidance.

Hey @DaveJha

That message would indicate that youā€™re pointing your browser at localhost:8000 not localhost:8888

Are you using Netlify CLI and running your project with the CLI command netlify dev?

@jonsulty Yes, using netlify dev and then gatsby develop as my subsequent start command.

Could elaborate on that a bit? Iā€™m not sure what you mean by subsequent start command - Netlify Dev should fire up Gastby for you, then youā€™d view the local site on localhost:8888

@jonsully Yes, I have several different start commands after running netlify dev, I choose gatsby/yarn develop which is what initiates. localhost:8888 (the server) starts, but does not let me look at the website (it draws blank). the development build is visible on 8000 as well as the CMS on localhost:8000/admin/#

@DaveJha Iā€™d recommend giving this a read -

Netlify Dev is made to start your development server for you, not setup such that you should start the development server yourself after you start Netlify Dev. If a blank screen is rendering on localhost:8888, something is wrong.

ā€“
Jon

Hi Jon,

I was able to resolve the issues with netlify dev and now it works as intended. Thank you for sending that resource. I (was) still unable to access the CMS with the same error as before using localhost:8888.

I did some more digging and realized that with the URL changes from earlier this year, I needed to set the URL to be my Netlify URL ā€“ not the URL I bought as a separate domain.

So, for anyone else who stumbles on this thread, try the following:

  1. Run localStorage.removeItem(ā€œnetlifySiteURLā€) in your browser console and refresh to reset the URL
  2. Set the URL to be your Netlify URL and not your domain ā€“ should look like site-name.netlify.app

Hi, I am running into issue as well:

Access to fetch at 'https://SITE_NAME.netlify.app/.netlify/identity/settings' from origin 'http://localhost:8888' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: It does not have HTTP ok status.

I am trying to setup Netlify CMS and run it locally. Deploying it and using it from the netlify.app domain works like a charm. I tried to re-link the repo, re-enable Git Gateway, set headers in netlify.toml but none of these helped. Itā€™s already like 10 hours for me trying to solve the issue and I still can not find the solution.

Using:

https://identity.netlify.com/v1/netlify-identity-widget.js
https://unpkg.com/netlify-cms@^2.0.0/dist/netlify-cms.js
Ubuntu Focal 20.04 (default)
netlify-cli/6.7.7 darwin-x64 node-v14.15.5

Alright, I finally solved it - this doc says everything about running Netlify CMS locally:

Works perfectly! It was hard to find though :smiley: