File tree 1 file changed +13
-4
lines changed
1 file changed +13
-4
lines changed Original file line number Diff line number Diff line change 1
1
import React , { useState , useEffect } from 'react' ;
2
2
3
+ const code = window . location . search . split ( '=' ) [ 1 ] ;
4
+
5
+ console . log ( localStorage . getItem ( 'access_token' ) ) ;
6
+
3
7
4
8
const Loader = ( ) => {
5
9
return (
@@ -10,24 +14,29 @@ const Loader = () => {
10
14
11
15
export const App = ( ) => {
12
16
const [ data , setData ] = useState ( null ) ;
17
+
13
18
useEffect ( ( ) => {
14
19
15
20
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
+ } } ) ;
17
27
}
18
28
19
29
getData ( ) . then ( ( res ) => {
20
- return res
30
+ return res . json ( )
21
31
} ) . then ( ( data ) => {
22
32
console . log ( data ) ;
23
- // setData(data);
24
33
} ) . catch ( ( e ) => {
25
34
console . log ( 'error: ' , e ) ;
26
35
} )
27
36
28
37
} , [ ] ) ;
29
38
30
39
31
-
40
+ return < h1 > Hi there! </ h1 >
32
41
return data === null ? < Loader /> : < div > { data } </ div >
33
42
}
You can’t perform that action at this time.
0 commit comments