Spaces:
Runtime error
Runtime error
Upload pages/api/auth/callback.js with huggingface_hub
Browse files- pages/api/auth/callback.js +36 -0
pages/api/auth/callback.js
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import axios from 'axios';
|
| 2 |
+
|
| 3 |
+
export default async function handler(req, res) {
|
| 4 |
+
const { code } = req.query;
|
| 5 |
+
const { clientId, clientSecret, redirectUri } = req.body;
|
| 6 |
+
|
| 7 |
+
if (!code) {
|
| 8 |
+
return res.status(400).json({ error: 'No code provided' });
|
| 9 |
+
}
|
| 10 |
+
|
| 11 |
+
try {
|
| 12 |
+
const response = await axios.post(
|
| 13 |
+
'https://accounts.spotify.com/api/token',
|
| 14 |
+
new URLSearchParams({
|
| 15 |
+
grant_type: 'authorization_code',
|
| 16 |
+
code: code,
|
| 17 |
+
redirect_uri: redirectUri,
|
| 18 |
+
client_id: clientId,
|
| 19 |
+
client_secret: clientSecret,
|
| 20 |
+
}),
|
| 21 |
+
{
|
| 22 |
+
headers: {
|
| 23 |
+
'Content-Type': 'application/x-www-form-urlencoded',
|
| 24 |
+
},
|
| 25 |
+
}
|
| 26 |
+
);
|
| 27 |
+
|
| 28 |
+
res.status(200).json(response.data);
|
| 29 |
+
} catch (error) {
|
| 30 |
+
console.error('Token exchange error:', error.response?.data || error.message);
|
| 31 |
+
res.status(500).json({
|
| 32 |
+
error: 'Failed to exchange token',
|
| 33 |
+
details: error.response?.data
|
| 34 |
+
});
|
| 35 |
+
}
|
| 36 |
+
}
|