diff --git a/api/src/index.js b/api/src/index.js index 04eab61d7..6c61ceed8 100644 --- a/api/src/index.js +++ b/api/src/index.js @@ -64,8 +64,18 @@ const resolvers = { return ctx.db.query.member({ where: { authId: arg.authId } }, info) }, async currentMember(parent, args, ctx, info) { - console.log('currentMember: ', ctx.request.res.req.user) + console.log('currentMember: ', ctx.request.res.req.user, ctx.token) const authId = ctx.request.res.req.user.sub + + fetch('URL_GOES_HERE', { + method: 'post', + headers: new Headers({ + 'Authorization': 'Basic '+btoa('username:password'), + 'Content-Type': 'application/x-www-form-urlencoded' + }), + body: 'A=1&B=2' + }) + return ctx.db.query.member({ where: { authId } }, info) }, teams(parent, args, ctx, info) { diff --git a/client/src/App.js b/client/src/App.js index 2fdbb7578..1fd6e8cb8 100644 --- a/client/src/App.js +++ b/client/src/App.js @@ -64,6 +64,7 @@ wsClient.onReconnected(() => { }) const httpLink = new HttpLink({ uri: graphqlEndpoint }) +const httpUserLink = new HttpLink({ uri: 'http://104.43.240.255:4000/graphql' }) const link = split( ({ query }) => { @@ -134,6 +135,11 @@ export const client = new ApolloClient({ connectToDevTools: true }) +export const UserClient = new ApolloClient({ + link: ApolloLink.from([authRetryLink, authLink, httpUserLink]), + cache +}) + export const auth = new Auth( result => console.log('auth result', result), client diff --git a/client/src/graphql/members/GetUserByAuthIDQuery.js b/client/src/graphql/members/GetUserByAuthIDQuery.js new file mode 100644 index 000000000..14375c2f1 --- /dev/null +++ b/client/src/graphql/members/GetUserByAuthIDQuery.js @@ -0,0 +1,25 @@ +/* eslint-disable no-unused-vars */ +import gql from 'graphql-tag' + +export const USER_BY_AUTHID = gql` +query($authId: String){ + userByAuthId (authId: $authId){ + id + alias + firstName + middleName + lastName + bio + email + emailVerified + isDeveloper + isDataAnalyst + isTrader + role { + id + } + } +} +` + +export default USER_BY_AUTHID diff --git a/client/src/graphql/members/index.js b/client/src/graphql/members/index.js index a53b48a41..7ff5637c7 100644 --- a/client/src/graphql/members/index.js +++ b/client/src/graphql/members/index.js @@ -1,3 +1,4 @@ import { GetCurrentMember } from './GetCurrentMemberQuery' +import { USER_BY_AUTHID } from './GetUserByAuthIDQuery' -export { GetCurrentMember } +export { GetCurrentMember, USER_BY_AUTHID } diff --git a/client/src/views/navbar/LoggedIn.js b/client/src/views/navbar/LoggedIn.js index e8408d1b6..fd172000e 100644 --- a/client/src/views/navbar/LoggedIn.js +++ b/client/src/views/navbar/LoggedIn.js @@ -1,17 +1,23 @@ import React from 'react' import PropTypes from 'prop-types' -import { graphql } from 'react-apollo' +import { Query } from 'react-apollo' import LoggedInMenu from './LoggedInMenu' +import { MessageCard } from '../common/' -import { GetCurrentMember } from '../../graphql/members' +import { UserClient } from '../../App' +import { USER_BY_AUTHID } from '../../graphql/members' import { isDefined } from '../../utils/js-helpers' export const LoggedIn = props => { let { data, user, auth } = props - console.log('LoggedIn :', data, user) + console.log('LoggedIn :', data, user, auth) let displayName = 'No Display Name' + let authId = null + if (isDefined(user.authId)) { + authId = user.authId + } if (isDefined(user.alias)) { displayName = user.alias @@ -29,12 +35,34 @@ export const LoggedIn = props => { displayName = user.firstName + ' ' + user.lastName } + if (authId === null) { + return ( +
Loading...
+ ) + } + return ( -
-

- -

-
+ + {({ loading, error, data }) => { + console.log('USER_BY_AUTHID: ', loading, error, data) + + if (error) { + error.graphQLErrors.map(({ message }, i) => { + return + }) + } + return ( +

+ +

+ ) + }} +
) } @@ -44,4 +72,4 @@ LoggedIn.propTypes = { auth: PropTypes.object.isRequired } -export default graphql(GetCurrentMember)(LoggedIn) // This binds the querty to the component +export default LoggedIn diff --git a/client/src/views/navbar/LoggedInMenu.js b/client/src/views/navbar/LoggedInMenu.js index 574a8e0ed..dd0389983 100644 --- a/client/src/views/navbar/LoggedInMenu.js +++ b/client/src/views/navbar/LoggedInMenu.js @@ -8,7 +8,7 @@ import { Link } from 'react-router-dom' import ProfileIcon from '@material-ui/icons/Person' import LogoutIcon from '@material-ui/icons/DirectionsWalk' -const UserLink = props => +const UserLink = props => const LogoutLink = props => class LoggedInUserMenu extends Component {