import './css/site.css' ; import 'bootstrap' ; import * as React from 'react' ; import * as ReactDOM from 'react-dom' ; import { browserHistory , Router } from 'react-router' ; import { Provider } from 'react-redux' ; import { syncHistoryWithStore } from 'react-router-redux' ; import routes from './routes' ; import configureStore from './configureStore' ; import { ApplicationState } from './store' ; import AuthenticationContext from 'adal-angular' ; import adalConfig from './adal/adalConfig' ; import AuthContext from 'adal-angular' ; import axios from "axios" ; const resourceId = 'https://ashishpslalom.onmicrosoft.com/InvoiceApi' ; const initialState = ( window as any ) . initialReduxState as ApplicationState ; const store = configureStore ( initialState ) ; const history = syncHistoryWithStore ( browserHistory , store ) ; ( window as any ) . AuthenticationContext = AuthContext ; let authContext = new AuthContext ( adalConfig ) ; axios . interceptors . response . use ( undefined , err => { if ( err . response . status === 401 && err . response . config && ! err . response . config . __isRetryRequest ) { err . response . config . __isRetryRequest = true ; return new Promise ( ( resolve , reject ) => { authContext . acquireToken ( resourceId , ( message , token , msg ) => { axios . defaults . headers . common [ 'Authorization' ] = `Bearer ${ token }` ; err . config . headers . Authorization = `Bearer ${ token }` ; axios ( err . config ) . then ( resolve , reject ) ; } ) ; } ) ; } throw err ; } ) ; authContext . handleWindowCallback ( ) ; if ( ! authContext . isCallback ( window . location . hash ) ) { if ( ! authContext . getCachedToken ( adalConfig . clientId ) || ! authContext . getCachedUser ( ) ) { authContext . login ( ) ; } else { ReactDOM . render ( < Provider store = { store } > < Router history = { browserHistory } children = { routes } > < /Router> < /Provider>, document.getElementById('react-app')); } }