Announcements

Help Wizard

Step 1

NEXT STEP

Invalid Client Error only on when deployed on Vercel

Invalid Client Error only on when deployed on Vercel

I am currently working on a project which fetches data from the Spotify API, and my requests work perfectly fine when run locally, but when I deploy my app to Vercel and try to use a live version of the project, the requests are currently failing with an "An authentication error occurred while communicating with Spotify's Web API.\nDetails: invalid_client Invalid client." error message.

 

This error does not occur when run locally with the exact same ID and secret, and the live version didn't even have this error a couple days ago, I went to test something on the live version after a couple days off, and all of a sudden I get this error every time I try to interact with the API. I am positive that the live version was working perfectly fine before, and nothing changed to cause this sudden error. The requests still work perfectly fine when run locally as well. I have even tried deploying to netlify as well, and it seems to work on netlify as well. Unfortunately Netlify charges for many of the features that are free with Vercel, so I would like to avoid migrating my app there if at all possible. Any idea what could be causing this?

Reply
6 Replies

Do you have added the Vercel callback url to the dashboard of your app? (Make sure to hit Save at the bottom after adding it.)

So adding the main Vercel URL as a Redirect URI on the Spotify developer dashboard should help?

or do I need to add the api endpoint url to Redirect URIs? (i.e. 'www.url.com/api/function')

The URI needs to be the same as the URL the Access Token needs to be sent to after you log in. This must be the same as the redirect URI you have written in your code.

I am not sending any access tokens back and forth because this project only involves fetching public data. I just send the client ID and client secret.  I am still unsure of what you mean by Redirect URI in my code though. 

With Client Credentials you don't need to add the redirect URI.

Where are your client_id and client_secret stored? Maybe your app can't reach them when deployed on Vercel, if they aren't hard-coded in your app.

Suggested posts