diff --git a/js-frontend/src/actions/configure.js b/js-frontend/src/actions/configure.js
index ef72350..096e5de 100644
--- a/js-frontend/src/actions/configure.js
+++ b/js-frontend/src/actions/configure.js
@@ -7,6 +7,12 @@ import {
authenticateComplete,
authenticateError
} from "./authenticate";
+
+import {
+ retrieveData,
+} from "../utils/sessionStorage";
+
+
import {applyConfig} from "../utils/clientSettings";
//import {
@@ -25,11 +31,11 @@ export const STORE_CURRENT_ENDPOINT_KEY = "STORE_CURRENT_ENDPOINT_KEY";
export function setEndpointKeys(endpoints, currentEndpointKey, defaultEndpointKey) {
return { type: SET_ENDPOINT_KEYS, endpoints, currentEndpointKey, defaultEndpointKey };
-};
+}
export function storeCurrentEndpointKey(currentEndpointKey) {
return { type: STORE_CURRENT_ENDPOINT_KEY, currentEndpointKey };
-};
+}
export function configure(endpoint={}, settings={}) {
@@ -49,15 +55,19 @@ export function configure(endpoint={}, settings={}) {
let {authRedirectPath, authRedirectHeaders} = getRedirectInfo(window.location);
- if (authRedirectPath) {
- dispatch(pushState(null, authRedirectPath));
- }
+ // TODO: FiX!
+ //if (authRedirectPath) {
+ // dispatch(pushState(null, authRedirectPath));
+ //}
- if (authRedirectHeaders && authRedirectHeaders["access-token"]) {
- debugger;
+ const currentHeaders = retrieveData(C.SAVED_CREDS_KEY) || {};
+
+ //if (authRedirectHeaders && authRedirectHeaders["access-token"]) {
+ if (currentHeaders && currentHeaders["access-token"]) {
settings.initialCredentials = {
- ...settings.initialCredentials,
- ...authRedirectHeaders
+ ...(settings.initialCredentials || {}),
+ ...authRedirectHeaders,
+ ...currentHeaders
};
}
diff --git a/js-frontend/src/actions/entities.js b/js-frontend/src/actions/entities.js
new file mode 100644
index 0000000..f67f8ea
--- /dev/null
+++ b/js-frontend/src/actions/entities.js
@@ -0,0 +1,8 @@
+/**
+ * Created by andrew on 27/02/16.
+ */
+import T from '../constants/ACTION_TYPES';
+
+export function entityReceived(id, entity) {
+ return { type: T.ENTITIES.RECEIVED };
+}
\ No newline at end of file
diff --git a/js-frontend/src/actions/signIn.js b/js-frontend/src/actions/signIn.js
index f9c3eb1..2ec0998 100644
--- a/js-frontend/src/actions/signIn.js
+++ b/js-frontend/src/actions/signIn.js
@@ -7,6 +7,7 @@ import {
getCurrentEndpointKey
} from "../utils/sessionStorage";
+import { entityReceived } from './entities';
import { storeCurrentEndpointKey } from "./configure";
import { parseResponse } from "../utils/handleFetchResponse";
import fetch from "../utils/fetch";
@@ -53,13 +54,22 @@ export function emailSignIn(body) {
},
method: "post",
body: root.JSON.stringify(body)
- })
- .then(parseResponse)
- .then(function(K) {
- debugger;
- return K;
+ }).then(parseResponse)
+ .then(function(data = {}) {
+ const { id, customerInfo } = data;
+ if (id && customerInfo) {
+ const user = {
+ ...customerInfo,
+ uid: id
+ };
+ dispatch(entityReceived(id, user));
+ return user;
+ }
+ return data;
+ })
+ .then((user) => {
+ dispatch(emailSignInComplete(user));
})
- .then((user) => dispatch(emailSignInComplete(user)))
.catch((errors) => {
// revert endpoint key to what it was before failed request
setCurrentEndpointKey(prevEndpointKey);
diff --git a/js-frontend/src/constants/ACTION_TYPES.js b/js-frontend/src/constants/ACTION_TYPES.js
index 25da68e..458d469 100644
--- a/js-frontend/src/constants/ACTION_TYPES.js
+++ b/js-frontend/src/constants/ACTION_TYPES.js
@@ -19,6 +19,9 @@ export default defineActionTypes({
SIGN_OUT_COMPLETE
`,
+ ENTITIES: `
+ RECEIVED
+ `,
DOCUMENT_LIST_VIEW: `
SET_QUERY
`,
diff --git a/js-frontend/src/reducers/auth/user.js b/js-frontend/src/reducers/auth/user.js
index 05584e5..9b35470 100644
--- a/js-frontend/src/reducers/auth/user.js
+++ b/js-frontend/src/reducers/auth/user.js
@@ -14,16 +14,15 @@ export const userReducer = (state = {...userInitalState}, action) => {
const { user } = action;
return {...state,
attributes: user,
- isSignedIn: true
+ isSignedIn: !!user
};
}
case T.AUTH.SIGN_IN_COMPLETE: {
-
const { user } = action;
return {...state,
- attributes: user.data,
- isSignedIn: true
+ attributes: user,
+ isSignedIn: !!user
};
}
case T.AUTH.SIGN_OUT_COMPLETE:
diff --git a/js-frontend/src/utils/fetch.js b/js-frontend/src/utils/fetch.js
index 00587ec..4ee2a64 100644
--- a/js-frontend/src/utils/fetch.js
+++ b/js-frontend/src/utils/fetch.js
@@ -17,15 +17,20 @@ import {
function getAuthHeaders(url) {
if (isApiRequest(url)) {
// fetch current auth headers from storage
- const currentHeaders = retrieveData(C.SAVED_CREDS_KEY) || {},
+ let currentHeaders = retrieveData(C.SAVED_CREDS_KEY) || {},
nextHeaders = {};
+ if (currentHeaders === 'undefined') {
+ currentHeaders = {};
+ }
// bust IE cache
nextHeaders["If-Modified-Since"] = "Mon, 26 Jul 1997 05:00:00 GMT";
// set header for each key in `tokenFormat` config
for (var key in getTokenFormat()) {
- nextHeaders[key] = currentHeaders[key];
+ if (key in currentHeaders) {
+ nextHeaders[key] = currentHeaders[key];
+ }
}
return nextHeaders;
@@ -35,6 +40,7 @@ function getAuthHeaders(url) {
}
function updateAuthCredentials(resp) {
+
// check config apiUrl matches the current response url
if (isApiRequest(resp.url)) {
// set header for each key in `tokenFormat` config
diff --git a/js-frontend/src/utils/parseUrl.js b/js-frontend/src/utils/parseUrl.js
index 0ae8021..4e98732 100644
--- a/js-frontend/src/utils/parseUrl.js
+++ b/js-frontend/src/utils/parseUrl.js
@@ -26,7 +26,7 @@ export function normalizeTokenKeys (params) {
};
const getAnchorSearch = function(location) {
- const rawAnchor = location.anchor || "",
+ const rawAnchor = location.hash || "",
arr = rawAnchor.split("?");
return (arr.length > 1) ? arr[1] : null;
};
diff --git a/js-frontend/src/utils/sessionStorage.js b/js-frontend/src/utils/sessionStorage.js
index b3bfeea..a4464d9 100644
--- a/js-frontend/src/utils/sessionStorage.js
+++ b/js-frontend/src/utils/sessionStorage.js
@@ -173,4 +173,4 @@ export function retrieveData (key) {
// unescape quotes
return unescapeQuotes(val);
}
-};
\ No newline at end of file
+}
\ No newline at end of file
diff --git a/js-frontend/src/views/Account.js b/js-frontend/src/views/Account.js
index c5acc92..243bcd2 100644
--- a/js-frontend/src/views/Account.js
+++ b/js-frontend/src/views/Account.js
@@ -44,6 +44,8 @@ export class Account extends React.Component {
render () {
+ debugger;
+
const { showAccountModal } = this.state;
return (
diff --git a/js-frontend/src/views/MyAccounts.js b/js-frontend/src/views/MyAccounts.js
index 7611d1d..86c217e 100644
--- a/js-frontend/src/views/MyAccounts.js
+++ b/js-frontend/src/views/MyAccounts.js
@@ -76,6 +76,18 @@ class MyAccounts extends React.Component {
//const deployTooltip = (
// Create a new instance of this demo on your own Heroku server.
//);
+ debugger;
+ const user = this.props.auth.user.attributes;
+ const {
+ email,
+ ssn,
+ name
+ } = user;
+ const {
+ firstName,
+ lastName
+ } = name;
+
const { showAccountModal, show3rdPartyAccountModal, showDeleteAccountModal } = this.state;
const { accountToRemove = null } = this.state;
@@ -97,17 +109,17 @@ class MyAccounts extends React.Component {
Customer:
- Kevin McCallister
+ { `${firstName} ${lastName}` }
Email:
- current@email.com
+ { email }
SSN:
- 1234567890-09876
+ { ssn }
@@ -217,6 +229,7 @@ class MyAccounts extends React.Component {
export default connect(({auth, demoUi = new Map()}) => {
return ({
+ auth,
currentUserUid: auth.user && auth.user.attributes && auth.user.attributes.provider || "none",
currentUserProvider: auth.user && auth.user.attributes && auth.user.attributes.uid || "none",
currentUserEndpoint: "none",
diff --git a/js-frontend/src/views/SignIn.js b/js-frontend/src/views/SignIn.js
index 853df5a..e3a5f89 100644
--- a/js-frontend/src/views/SignIn.js
+++ b/js-frontend/src/views/SignIn.js
@@ -9,6 +9,8 @@ import { connect } from "react-redux";
import { Input } from "react-bootstrap";
import * as BS from "react-bootstrap";
+import {pushState} from "redux-router";
+
import ButtonLoader from "../controls/bootstrap/ButtonLoader";
//export {bootstrap, materialUi} from "./views";
@@ -21,9 +23,14 @@ import EmailSignInForm from "../controls/bootstrap/EmailSignInForm";
export class SignIn extends React.Component {
componentWillMount() {
- if (this.props.isAuthenticated) {
+ }
+
+ componentWillReceiveProps(nextProps) {
+ if (nextProps.auth.user.isSignedIn) {
+//debugger;
+ this.props.dispatch(pushState(null, nextProps.location.query.next));
//// redirect to login and add next param so we can redirect again after login
//const redirectAfterLogin = this.props.location.pathname;
//this.props.dispatch(pushState(null, `/signin?next=${redirectAfterLogin}`));
@@ -51,9 +58,11 @@ export class SignIn extends React.Component {
}
}
export default connect(({
+ //dispatch,
routes,
auth
}) => ({
+ //dispatch,
routes,
auth
}))(SignIn);