File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 77 },
88 "dependencies" : {
99 "auth0-js" : " ^8.7.0" ,
10+ "axios" : " ^0.16.2" ,
1011 "bootstrap" : " ^3.3.7" ,
1112 "cors" : " ^2.8.3" ,
1213 "dotenv" : " ^4.0.0" ,
Original file line number Diff line number Diff line change @@ -23,7 +23,6 @@ export default class Auth {
2323 this . userHasScopes = this . userHasScopes . bind ( this ) ;
2424 this . getAccessToken = this . getAccessToken . bind ( this ) ;
2525 this . getProfile = this . getProfile . bind ( this ) ;
26- this . authFetch = this . authFetch . bind ( this ) ;
2726 }
2827
2928 login ( ) {
@@ -102,29 +101,4 @@ export default class Auth {
102101 const grantedScopes = JSON . parse ( localStorage . getItem ( 'scopes' ) ) . split ( ' ' ) ;
103102 return scopes . every ( scope => grantedScopes . includes ( scope ) ) ;
104103 }
105-
106- authFetch ( url , options ) {
107- const headers = {
108- Accept : 'application/json' ,
109- 'Content-Type' : 'application/json'
110- } ;
111-
112- if ( this . isAuthenticated ( ) ) {
113- headers [ 'Authorization' ] = 'Bearer ' + this . getAccessToken ( ) ;
114- }
115-
116- return fetch ( url , { headers, ...options } )
117- . then ( this . checkStatus )
118- . then ( response => response . json ( ) ) ;
119- }
120-
121- checkStatus ( response ) {
122- if ( response . status >= 200 && response . status < 300 ) {
123- return response ;
124- } else {
125- let error = new Error ( response . statusText ) ;
126- error . response = response ;
127- throw error ;
128- }
129- }
130104}
Original file line number Diff line number Diff line change 11import React , { Component } from 'react' ;
22import { Button } from 'react-bootstrap' ;
33import { API_URL } from './../constants' ;
4+ import axios from 'axios' ;
45
56class Ping extends Component {
67 componentWillMount ( ) {
78 this . setState ( { message : '' } ) ;
89 }
910 ping ( ) {
10- fetch ( `${ API_URL } /public` )
11- . then ( res => res . json ( ) )
12- . then ( data => this . setState ( { message : data . message } ) ) ;
11+ axios . get ( `${ API_URL } /public` )
12+ . then ( response => this . setState ( { message : response . data . message } ) )
13+ . catch ( error => this . setState ( { message : error . message } ) ) ;
1314 }
1415 securedPing ( ) {
15- const { authFetch } = this . props . auth ;
16- authFetch ( `${ API_URL } /private` )
17- . then ( data => this . setState ( { message : data . message } ) )
16+ const { getAccessToken } = this . props . auth ;
17+ const headers = { 'Authorization' : `Bearer ${ getAccessToken ( ) } ` }
18+ axios . get ( `${ API_URL } /private` , { headers } )
19+ . then ( response => this . setState ( { message : response . data . message } ) )
1820 . catch ( error => this . setState ( { message : error . message } ) ) ;
1921 }
2022 render ( ) {
You can’t perform that action at this time.
0 commit comments