Det9999's picture
Upload pages/api/auth/callback.js with huggingface_hub
972d774 verified
raw
history blame contribute delete
930 Bytes
import axios from 'axios';
export default async function handler(req, res) {
const { code } = req.query;
const { clientId, clientSecret, redirectUri } = req.body;
if (!code) {
return res.status(400).json({ error: 'No code provided' });
}
try {
const response = await axios.post(
'https://accounts.spotify.com/api/token',
new URLSearchParams({
grant_type: 'authorization_code',
code: code,
redirect_uri: redirectUri,
client_id: clientId,
client_secret: clientSecret,
}),
{
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
},
}
);
res.status(200).json(response.data);
} catch (error) {
console.error('Token exchange error:', error.response?.data || error.message);
res.status(500).json({
error: 'Failed to exchange token',
details: error.response?.data
});
}
}