# Cross-Origin Request Blocked with spotify API

**URL:** <https://forum.freecodecamp.org/t/cross-origin-request-blocked-with-spotify-api/417225>\
**Category:** General\
**Created:** [August 25, 2020, 4:29pm UTC](https://forum.freecodecamp.org/t/cross-origin-request-blocked-with-spotify-api/417225 "2020-08-25T16:29:11Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Remold](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/remold/32/136566_2.png) [@Remold](https://forum.freecodecamp.org/u/Remold)\
**Post date:** [August 25, 2020, 4:29pm UTC](https://forum.freecodecamp.org/t/cross-origin-request-blocked-with-spotify-api/417225/1 "2020-08-25T16:29:11Z")

</div>

Hi,  
I’m trying to create an application (front and back) where at some point the user click to connect to spotify which “hits” the route /spotify on the back-end and the oauth thing is supposed to start but I keep getting those CORS errors.  
My front is localhost:3001, back localhost:3000

The error message from firefox :

> Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at [Login - Spotify](https://accounts.spotify.com/authorize?response_type=code&client_id=CLIENT_KEY&scope=user-read-private&redirect_uri=https%3A%2F%2Flocalhost%3A3000%2Fcallback&state=1btxz1elydu). (Reason: CORS header ‘Access-Control-Allow-Origin’ missing).

and my code :

- Front

```auto
fetch("http://localhost:3000/spotify", {
      method: "GET",
      origin: "https://localhost:3001",
      credentials: "include",
    }).catch((err) => console.error(err));

```

- Back

```auto
app.use(
  cors({
    origin: process.env.CORS, // http://localhost:3001 
  })
);

const stateKey = "spotify_auth_state";

app.get("/spotify", (req, res) => {
  // generates states and set it in cookie
  const state = genState();
  res.set({
    "Access-Control-Allow-Credentials": "true",
    "Access-Control-Allow-Origin": "http://localhost:3001",
  });
  res.cookie(stateKey, state);

  // Authorization request
  const scope = "user-read-private";
  res.redirect(
    "https://accounts.spotify.com/authorize?" +
      querystring.stringify({
        response_type: "code",
        client_id: client_id,
        scope: scope,
        redirect_uri: redirect_uri,
        state: state,
      })
  );
});

```

I’ve been trying a lot and nothing works. Please help me!

---

<div class="post-metadata">

**Author:** ![CactusWren2020](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/cactuswren2020/32/144687_2.png) [@CactusWren2020](https://forum.freecodecamp.org/u/CactusWren2020)\
**Post date:** [August 25, 2020, 4:32pm UTC](https://forum.freecodecamp.org/t/cross-origin-request-blocked-with-spotify-api/417225/2 "2020-08-25T16:32:21Z")

</div>

As a workaround, you might try a proxy server and see what happens. I’ve only done it once, and it slowed things down significantly, but at least it worked!

> **[10 Free to Use CORS Proxies | Nordic APIs |](https://nordicapis.com/10-free-to-use-cors-proxies/)**
>
> When developing applications, a CORS error can be one of the most annoying and workflow-breaking errors to come across. Here are some free CORS proxies to help

---

<div class="post-metadata">

**Author:** ![tealjulia](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/tealjulia/32/147521_2.png) [@tealjulia](https://forum.freecodecamp.org/u/tealjulia)\
**Post date:** [February 15, 2021, 7:14pm UTC](https://forum.freecodecamp.org/t/cross-origin-request-blocked-with-spotify-api/417225/3 "2021-02-15T19:14:09Z")

</div>

Did you end up figuring this out? I’m hitting a similar CORS issue with Spotify/OAuth

---

<div class="post-metadata">

**Author:** ![Remold](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/remold/32/136566_2.png) [@Remold](https://forum.freecodecamp.org/u/Remold)\
**Post date:** [February 16, 2021, 8:11am UTC](https://forum.freecodecamp.org/t/cross-origin-request-blocked-with-spotify-api/417225/4 "2021-02-16T08:11:46Z")

</div>

Yeah but it was a while ago 😅, so basically if you get cors error it’s coming from your browser.  
There is different options:

- you can get an extension on your favorite browser called “CORS Everywhere”
- You have to authorize your app in your Spotify developer account (so if you develop locally you need to add like localhost)

I cannot really help more I can’t really remember and I’m always struggling with this cors error

---

<div class="post-metadata">

**Author:** ![ILM](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/ilm/32/363239_2.png) [@ILM](https://forum.freecodecamp.org/u/ILM)\
**Post date:** [June 1, 2021, 6:42pm UTC](https://forum.freecodecamp.org/t/cross-origin-request-blocked-with-spotify-api/417225/5 "2021-06-01T18:42:56Z")

</div>

Closed on June 1, 2021, 6:42pm UTC


