forked from Remchi/bookworm-react
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
40 lines (37 loc) · 1.18 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import React from "react";
import ReactDOM from "react-dom";
import { BrowserRouter, Route } from "react-router-dom";
import "semantic-ui-css/semantic.min.css";
import { createStore, applyMiddleware } from "redux";
import { Provider } from "react-redux";
import thunk from "redux-thunk";
import decode from "jwt-decode";
import { composeWithDevTools } from "redux-devtools-extension";
import App from "./App";
import registerServiceWorker from "./registerServiceWorker";
import rootReducer from "./rootReducer";
import { userLoggedIn } from "./actions/auth";
import setAuthorizationHeader from "./utils/setAuthorizationHeader";
const store = createStore(
rootReducer,
composeWithDevTools(applyMiddleware(thunk))
);
if (localStorage.bookwormJWT) {
const payload = decode(localStorage.bookwormJWT);
const user = {
token: localStorage.bookwormJWT,
email: payload.email,
confirmed: payload.confirmed
};
setAuthorizationHeader(localStorage.bookwormJWT);
store.dispatch(userLoggedIn(user));
}
ReactDOM.render(
<BrowserRouter>
<Provider store={store}>
<Route component={App} />
</Provider>
</BrowserRouter>,
document.getElementById("root")
);
registerServiceWorker();