Skip to content

Commit

Permalink
feat: add optional connection_id to request header
Browse files Browse the repository at this point in the history
  • Loading branch information
cdrani committed May 15, 2024
1 parent ed15c7c commit e295e78
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions src/utils/request.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,23 @@
import { getState } from './state.js'

export const setOptions = async ({ method = 'GET', body = null }) => {
export const setOptions = async ({ method = 'GET', body = null, connect = false }) => {
const authHeader = await getAuthHeader()
const connectHeader = connect ? await getConnectHeader() : null

return {
method,
body: body ? JSON.stringify(body) : null,
headers: { Authorization: authHeader, 'Content-Type': 'application/json' },
headers: {
Authorization: authHeader,
'Content-Type': 'application/json',
...connect && { 'X-Spotify-Connection-Id': connectHeader },
},
}
}

const getAuthHeader = async () => {
const authHeader = await getState('auth_token')
return authHeader
}
const getAuthHeader = async () => await getState('auth_token')

const getConnectHeader = async () => await getState('connection_id')

export const request = async ({ url, options }) => {
try {
Expand Down

0 comments on commit e295e78

Please sign in to comment.