Auth service and MyAccounts show data

This commit is contained in:
Andrew Revinsky (DART)
2016-02-27 02:06:47 +03:00
parent e337f05c89
commit fb1069ebb9
11 changed files with 87 additions and 27 deletions

View File

@@ -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
};
}

View File

@@ -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 };
}

View File

@@ -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);

View File

@@ -19,6 +19,9 @@ export default defineActionTypes({
SIGN_OUT_COMPLETE
`,
ENTITIES: `
RECEIVED
`,
DOCUMENT_LIST_VIEW: `
SET_QUERY
`,

View File

@@ -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:

View File

@@ -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

View File

@@ -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;
};

View File

@@ -173,4 +173,4 @@ export function retrieveData (key) {
// unescape quotes
return unescapeQuotes(val);
}
};
}

View File

@@ -44,6 +44,8 @@ export class Account extends React.Component {
render () {
debugger;
const { showAccountModal } = this.state;
return (

View File

@@ -76,6 +76,18 @@ class MyAccounts extends React.Component {
//const deployTooltip = (<Tooltip>
// Create a new instance of this demo on your own Heroku server.
//</Tooltip>);
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 {
<Row>
<Col xs={4}>Customer:</Col>
<Col xs={8}><strong>Kevin McCallister</strong></Col>
<Col xs={8}><strong>{ `${firstName} ${lastName}` }</strong></Col>
</Row>
<Row>
<Col xs={4}>Email:</Col>
<Col xs={8}><strong>current@email.com</strong></Col>
<Col xs={8}><strong>{ email }</strong></Col>
</Row>
<Row>
<Col xs={4}>SSN:</Col>
<Col xs={8}><strong>1234567890-09876</strong></Col>
<Col xs={8}><strong>{ ssn }</strong></Col>
</Row>
@@ -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",

View File

@@ -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);