Personal Site
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

/callback now gets the refresh token from the result and writes that to ./.refreshToken because the ./.accessToken method wasnt working and its easier to just refresh access on start

+19 -21
+19 -21
src/pages/_callback.astro
··· 9 9 const userAuthCode = Astro.url.searchParams.get("code") ?? undefined; 10 10 11 11 if (userAuthCode) { 12 - fetch( 13 - "https://accounts.spotify.com/api/token", 14 - { 15 - method: "post", 16 - 17 - headers: { 18 - "content-type": "application/x-www-form-urlencoded", 19 - Authorization: 20 - "Basic " + 21 - Buffer.from(SPOTIFY_CLIENT_ID + ":" + SPOTIFY_CLIENT_SECRET).toString( 22 - "base64", 23 - ), 24 - }, 12 + fetch("https://accounts.spotify.com/api/token", { 13 + method: "post", 25 14 26 - body: new URLSearchParams({ 27 - code: userAuthCode, 28 - redirect_uri: SPOTIFY_REDIRECT_URI, 29 - grant_type: "authorization_code", 30 - }).toString(), 15 + headers: { 16 + "content-type": "application/x-www-form-urlencoded", 17 + Authorization: 18 + "Basic " + 19 + Buffer.from(SPOTIFY_CLIENT_ID + ":" + SPOTIFY_CLIENT_SECRET).toString( 20 + "base64", 21 + ), 31 22 }, 32 - ) 33 - .then((res) => res.text()) 23 + 24 + body: new URLSearchParams({ 25 + code: userAuthCode, 26 + redirect_uri: SPOTIFY_REDIRECT_URI, 27 + grant_type: "authorization_code", 28 + }).toString(), 29 + }) 30 + .then((res) => res.json()) 31 + .then((token) => token.refresh_token) 34 32 .then((token) => 35 - fs.writeFile("./.accessToken", token, { 33 + fs.writeFile("./.refreshToken", String(token), { 36 34 encoding: "utf-8", 37 35 }), 38 36 )