using background context

This commit is contained in:
2025-11-23 23:18:00 +00:00
parent 12f7a7a49e
commit a75e943e67

View File

@@ -1,6 +1,7 @@
package handlers package handlers
import ( import (
"context"
"net/http" "net/http"
"adam-french.co.uk/backend/services" "adam-french.co.uk/backend/services"
@@ -10,9 +11,10 @@ import (
func (store *Store) CompleteAuth(c *gin.Context) { func (store *Store) CompleteAuth(c *gin.Context) {
state := c.Query("state") state := c.Query("state")
ctx := context.Background()
// code := c.Query("code") // code := c.Query("code")
token, err := store.SpotifyAuth.Token(c.Request.Context(), state, c.Request) token, err := store.SpotifyAuth.Token(ctx, state, c.Request)
if err != nil { if err != nil {
c.String(http.StatusInternalServerError, "Couldn't get token: %v", err) c.String(http.StatusInternalServerError, "Couldn't get token: %v", err)
return return
@@ -20,7 +22,7 @@ func (store *Store) CompleteAuth(c *gin.Context) {
services.SaveSpotifyToken(services.SPOTIFY_TOKEN_JSON_PATH, token) services.SaveSpotifyToken(services.SPOTIFY_TOKEN_JSON_PATH, token)
client := spotify.New(store.SpotifyAuth.Client(c.Request.Context(), token)) client := spotify.New(store.SpotifyAuth.Client(ctx, token))
store.SpotifyClient = client store.SpotifyClient = client
@@ -70,6 +72,7 @@ func (store *Store) ListeningTo(c *gin.Context) {
c.JSON(200, gin.H{ c.JSON(200, gin.H{
"playing": true, "playing": true,
"song_name": item.Name, "song_name": item.Name,
"song_url": item.URI,
"artist_name": artistName, "artist_name": artistName,
"album_image": imgURL, "album_image": imgURL,
}) })