Skip to content

Commit 3ddc32d

Browse files
committed
feat: get params from url
1 parent 15f558c commit 3ddc32d

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

esbuild/src/components/App.jsx

+13-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
import React, { useState, useEffect } from 'react';
22

3+
const code = window.location.search.split('=')[1];
4+
5+
console.log(localStorage.getItem('access_token'));
6+
37

48
const Loader = () => {
59
return (
@@ -10,24 +14,29 @@ const Loader = () => {
1014

1115
export const App = () => {
1216
const [data, setData] = useState(null);
17+
1318
useEffect(() => {
1419

1520
async function getData() {
16-
return await fetch('https://api.spotify.com/v1/me');
21+
return await fetch('https://api.spotify.com/v1/me', {
22+
headers: {
23+
Authorization: `Bearer ${code}`,
24+
"Content-Type": "application/json",
25+
Host: "api.spotify.com"
26+
}});
1727
}
1828

1929
getData().then((res) => {
20-
return res
30+
return res.json()
2131
}).then((data) => {
2232
console.log(data);
23-
// setData(data);
2433
}).catch((e) => {
2534
console.log('error: ', e);
2635
})
2736

2837
}, []);
2938

3039

31-
40+
return <h1>Hi there!</h1>
3241
return data === null ? <Loader /> : <div>{data}</div>
3342
}

0 commit comments

Comments
 (0)