Spotify API calls using TRPC

Hi, I would like to make use the spotify API in my t3 app. The following repo shows how I would retrieve my token. https://github.com/spotify/web-api-auth-examples/blob/master/client_credentials/app.js Where would this be done in the stack? If there are docs highlighting this could you please point me to it? Thanks
GitHub
web-api-auth-examples/app.js at master · spotify/web-api-auth-examp...
Basic examples to authenticate and fetch data using the Spotify Web API - web-api-auth-examples/app.js at master · spotify/web-api-auth-examples
3 Replies
DunnO
DunnOOP3y ago
I would like this to be done in the back end since I am using secret keys
Keef
Keef3y ago
Anything done on the mutation/query side is done on the server so if you dont want to leak keys, keep that stuff in those methods. In this post you can just replace it with a mutation/query and its almost verbatim something like
router.query('getToken', {
input: z.object({
token: z.string()
})
resolve: async ()=> {
const request = await fetch(url,options)


return {
// something
}
}})
router.query('getToken', {
input: z.object({
token: z.string()
})
resolve: async ()=> {
const request = await fetch(url,options)


return {
// something
}
}})
Its v9 syntax since I havent upgraded yet shy basically everything you would do in a traditional endpoint, you just do in your query/mutation
DunnO
DunnOOP3y ago
Thank you!
Want results from more Discord servers?
Add your server