From 2437ac7a319cc4e645a3c972f80499b99ec75b24 Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Fri, 7 Sep 2018 11:22:37 +0200 Subject: [PATCH] Reading authId from local storage --- client/src/components/LoggedInUser.js | 3 ++- .../src/components/Material-UI/ButtonAppBar.js | 16 ++++++++++++++-- client/src/components/UserList.js | 4 +++- 3 files changed, 19 insertions(+), 4 deletions(-) diff --git a/client/src/components/LoggedInUser.js b/client/src/components/LoggedInUser.js index b4accdab0..bf718f60c 100644 --- a/client/src/components/LoggedInUser.js +++ b/client/src/components/LoggedInUser.js @@ -8,7 +8,8 @@ class LoggedInUser extends Component { displayLoggedInUser(){ const user = this.props.data.userByAuthId; - + console.log(this.props); + if(user){ if (user.firstName) { return( diff --git a/client/src/components/Material-UI/ButtonAppBar.js b/client/src/components/Material-UI/ButtonAppBar.js index feccfc8e9..da37c5338 100644 --- a/client/src/components/Material-UI/ButtonAppBar.js +++ b/client/src/components/Material-UI/ButtonAppBar.js @@ -43,8 +43,20 @@ const styles = { class ButtonAppBar extends Component { + constructor(props){ + super(props); + this.state = { + authId: null + } + } + componentDidMount() { - console.log('component did mount!'); + const getUser = window.localStorage.getItem("user"); + let user = JSON.parse(getUser) + const authId = user.sub; + + console.log(authId); + this.setState({ authId: authId }); } render() { @@ -68,7 +80,7 @@ class ButtonAppBar extends Component { - + diff --git a/client/src/components/UserList.js b/client/src/components/UserList.js index 5bba0e310..d49237d83 100644 --- a/client/src/components/UserList.js +++ b/client/src/components/UserList.js @@ -6,12 +6,14 @@ import {getUsersQuery} from '../queries/queries'; import UserProfile from './UserProfile'; class UserList extends Component { + constructor(props){ super(props); this.state = { selected: null } } + displayUsers(){ let data = this.props.data; @@ -28,8 +30,8 @@ class UserList extends Component { }); } } - render() { + render() { return (