<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic client credentials not refreshing token in Spotify for Developers</title>
    <link>https://community.spotify.com/t5/Spotify-for-Developers/client-credentials-not-refreshing-token/m-p/6162576#M14306</link>
    <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Device&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Operating System&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;Mac&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;My Question or Issue&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;I am attempting to use the web-api-ts-sdk inside a Nextjs server action. I am using the withClientCredentials(), which I would assume I would not need to refresh the access token. But I get the following error when trying to use the client, after successfully creating the client:&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;"Bad or expired token. This can happen if the user revoked a token or the access token has expired. You should re-authenticate the user."&lt;BR /&gt;&lt;BR /&gt;I am just trying to search something with the api, so not accessing user data.&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;export&lt;/SPAN&gt; &lt;SPAN&gt;const&lt;/SPAN&gt; &lt;SPAN&gt;createClient&lt;/SPAN&gt; &lt;SPAN&gt;=&lt;/SPAN&gt; &lt;SPAN&gt;async&lt;/SPAN&gt;&lt;SPAN&gt; () &lt;/SPAN&gt;&lt;SPAN&gt;=&amp;gt;&lt;/SPAN&gt;&lt;SPAN&gt; {&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;const cl&lt;/SPAN&gt; &lt;SPAN&gt;=&lt;/SPAN&gt; &lt;SPAN&gt;SpotifyApi&lt;/SPAN&gt;&lt;SPAN&gt;.&lt;/SPAN&gt;&lt;SPAN&gt;withClientCredentials&lt;/SPAN&gt;&lt;SPAN&gt;(&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;process&lt;/SPAN&gt;&lt;SPAN&gt;.&lt;/SPAN&gt;&lt;SPAN&gt;env&lt;/SPAN&gt;&lt;SPAN&gt;.&lt;/SPAN&gt;&lt;SPAN&gt;SPOTIFY_CLIENT_ID &lt;/SPAN&gt;&lt;SPAN&gt;??&lt;/SPAN&gt; &lt;SPAN&gt;""&lt;/SPAN&gt;&lt;SPAN&gt;,&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;process&lt;/SPAN&gt;&lt;SPAN&gt;.&lt;/SPAN&gt;&lt;SPAN&gt;env&lt;/SPAN&gt;&lt;SPAN&gt;.&lt;/SPAN&gt;&lt;SPAN&gt;SPOTIFY_CLIENT_SECRET &lt;/SPAN&gt;&lt;SPAN&gt;??&lt;/SPAN&gt; &lt;SPAN&gt;""&lt;/SPAN&gt;&lt;SPAN&gt;)&lt;/SPAN&gt;&lt;SPAN&gt;;&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;return&lt;/SPAN&gt; &lt;SPAN&gt;cl&lt;/SPAN&gt;&lt;SPAN&gt;;&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;}&lt;/SPAN&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 28 Jun 2024 18:04:46 GMT</pubDate>
    <dc:creator>mannypaz</dc:creator>
    <dc:date>2024-06-28T18:04:46Z</dc:date>
    <item>
      <title>client credentials not refreshing token</title>
      <link>https://community.spotify.com/t5/Spotify-for-Developers/client-credentials-not-refreshing-token/m-p/6162576#M14306</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Device&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Operating System&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;Mac&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;My Question or Issue&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;I am attempting to use the web-api-ts-sdk inside a Nextjs server action. I am using the withClientCredentials(), which I would assume I would not need to refresh the access token. But I get the following error when trying to use the client, after successfully creating the client:&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;"Bad or expired token. This can happen if the user revoked a token or the access token has expired. You should re-authenticate the user."&lt;BR /&gt;&lt;BR /&gt;I am just trying to search something with the api, so not accessing user data.&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;export&lt;/SPAN&gt; &lt;SPAN&gt;const&lt;/SPAN&gt; &lt;SPAN&gt;createClient&lt;/SPAN&gt; &lt;SPAN&gt;=&lt;/SPAN&gt; &lt;SPAN&gt;async&lt;/SPAN&gt;&lt;SPAN&gt; () &lt;/SPAN&gt;&lt;SPAN&gt;=&amp;gt;&lt;/SPAN&gt;&lt;SPAN&gt; {&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;const cl&lt;/SPAN&gt; &lt;SPAN&gt;=&lt;/SPAN&gt; &lt;SPAN&gt;SpotifyApi&lt;/SPAN&gt;&lt;SPAN&gt;.&lt;/SPAN&gt;&lt;SPAN&gt;withClientCredentials&lt;/SPAN&gt;&lt;SPAN&gt;(&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;process&lt;/SPAN&gt;&lt;SPAN&gt;.&lt;/SPAN&gt;&lt;SPAN&gt;env&lt;/SPAN&gt;&lt;SPAN&gt;.&lt;/SPAN&gt;&lt;SPAN&gt;SPOTIFY_CLIENT_ID &lt;/SPAN&gt;&lt;SPAN&gt;??&lt;/SPAN&gt; &lt;SPAN&gt;""&lt;/SPAN&gt;&lt;SPAN&gt;,&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;process&lt;/SPAN&gt;&lt;SPAN&gt;.&lt;/SPAN&gt;&lt;SPAN&gt;env&lt;/SPAN&gt;&lt;SPAN&gt;.&lt;/SPAN&gt;&lt;SPAN&gt;SPOTIFY_CLIENT_SECRET &lt;/SPAN&gt;&lt;SPAN&gt;??&lt;/SPAN&gt; &lt;SPAN&gt;""&lt;/SPAN&gt;&lt;SPAN&gt;)&lt;/SPAN&gt;&lt;SPAN&gt;;&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;return&lt;/SPAN&gt; &lt;SPAN&gt;cl&lt;/SPAN&gt;&lt;SPAN&gt;;&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;}&lt;/SPAN&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 28 Jun 2024 18:04:46 GMT</pubDate>
      <guid>https://community.spotify.com/t5/Spotify-for-Developers/client-credentials-not-refreshing-token/m-p/6162576#M14306</guid>
      <dc:creator>mannypaz</dc:creator>
      <dc:date>2024-06-28T18:04:46Z</dc:date>
    </item>
    <item>
      <title>Re: client credentials not refreshing token</title>
      <link>https://community.spotify.com/t5/Spotify-for-Developers/client-credentials-not-refreshing-token/m-p/6179861#M14388</link>
      <description>&lt;P&gt;Is that createClient fn within 'use server' file? Or do you import it into a 'use server' file and call it from within a server action definition?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I don't use server actions myself too often, but it might be a good idea to have the SDK client creation within the server action itself and not a separate function. That way it's always encapsulated in the server action execution and gets a fresh access token every time. Next.js can be funky sometimes&lt;BR /&gt;&lt;BR /&gt;```&lt;/P&gt;&lt;P&gt;"use server"&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;export const MyServerAction = async () =&amp;gt; {&lt;/P&gt;&lt;P&gt;// Start client within server action, not separate&lt;/P&gt;&lt;P&gt;const cl = await SpotifyApi.withClientCredentials(args...);&lt;/P&gt;&lt;P&gt;// Do stuff with client&lt;/P&gt;&lt;P&gt;return;&lt;/P&gt;&lt;P&gt;}&lt;/P&gt;&lt;P&gt;```&lt;/P&gt;</description>
      <pubDate>Sun, 07 Jul 2024 20:39:18 GMT</pubDate>
      <guid>https://community.spotify.com/t5/Spotify-for-Developers/client-credentials-not-refreshing-token/m-p/6179861#M14388</guid>
      <dc:creator>smacklol</dc:creator>
      <dc:date>2024-07-07T20:39:18Z</dc:date>
    </item>
  </channel>
</rss>

