|
|
@@ -1,20 +1,21 @@
|
|
|
import React from 'react';
|
|
|
import PropTypes from 'prop-types';
|
|
|
import { connect } from 'react-redux';
|
|
|
+import { decode } from 'jsonwebtoken';
|
|
|
import BodyWrapper from '../components/BodyWrapper';
|
|
|
import Footer from '../components/Footer';
|
|
|
import { authUser } from '../actions';
|
|
|
import Settings from '../components/Settings';
|
|
|
|
|
|
-const SettingsPage = ({ isAuthenticated }) => (
|
|
|
+const SettingsPage = ({ auth, isAuthenticated }) => console.log({auth}) || (
|
|
|
<BodyWrapper>
|
|
|
- {isAuthenticated ? <Settings /> : null}
|
|
|
+ {isAuthenticated ? <Settings /> : <PageLoading />}
|
|
|
<Footer />
|
|
|
</BodyWrapper>
|
|
|
);
|
|
|
|
|
|
SettingsPage.getInitialProps = ({ req, reduxStore }) => {
|
|
|
- const token = req && req.cookies && req.cookies.token;
|
|
|
+ const token = decode(req && req.cookies && req.cookies.token);
|
|
|
if (token && reduxStore) reduxStore.dispatch(authUser(token));
|
|
|
return {};
|
|
|
};
|
|
|
@@ -23,6 +24,6 @@ SettingsPage.propTypes = {
|
|
|
isAuthenticated: PropTypes.bool.isRequired,
|
|
|
};
|
|
|
|
|
|
-const mapStateToProps = ({ auth: { isAuthenticated } }) => ({ isAuthenticated });
|
|
|
+const mapStateToProps = ({ auth }) => ({ isAuthenticated: auth.isAuthenticated, auth });
|
|
|
|
|
|
export default connect(mapStateToProps)(SettingsPage);
|