Master App Integration part 2, user logged in working
This commit is contained in:
1 parent
20eb098966
commit
208d4f393d
2 files changed
+22
-6
No files matched your search
@@ -1,14 +1,14 @@
|
||||
import React, { Component } from 'react'
|
||||
import {graphql} from 'react-apollo'
|
||||
import {getUserByAuthIdQuery} from '../queries/queries'
|
||||
import {auth} from '../App'
|
||||
|
||||
import LoggedInUserMenu from './LoggedInUserMenu'
|
||||
import Button from '@material-ui/core/Button'
|
||||
|
||||
class LoggedInUser extends Component {
|
||||
|
||||
displayLoggedInUser () {
|
||||
const user = this.props.data.userByAuthId
|
||||
const user = this.props.data.users_UserByAuthId
|
||||
|
||||
if (user) {
|
||||
let displayName = 'No Display Name'
|
||||
@@ -40,7 +40,7 @@ class LoggedInUser extends Component {
|
||||
)
|
||||
} else {
|
||||
return (
|
||||
<div onClick={() => auth.login()}>
|
||||
<div>
|
||||
<Button color='inherit'>Login / Sign up</Button>
|
||||
</div>
|
||||
)
|
||||
@@ -52,11 +52,12 @@ class LoggedInUser extends Component {
|
||||
}
|
||||
|
||||
render () {
|
||||
console.log('props', this.props)
|
||||
if (this.loggedInUserStored !== true) {
|
||||
let user = this.props.data.userByAuthId
|
||||
let user = this.props.data.users_UserByAuthId
|
||||
|
||||
if (user !== undefined) {
|
||||
localStorage.setItem('loggedInUser', JSON.stringify(this.props.data.userByAuthId))
|
||||
localStorage.setItem('loggedInUser', JSON.stringify(this.props.data.users_UserByAuthId))
|
||||
this.loggedInUserStored = true
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,6 +16,9 @@ import UserIcon from '@material-ui/icons/Person'
|
||||
|
||||
import { Link } from 'react-router-dom'
|
||||
|
||||
// components
|
||||
import LoggedInUser from './LoggedInUser'
|
||||
|
||||
const UserLink = props => <Link to='/user' {...props} />
|
||||
const AboutLink = props => <Link to='/about' {...props} />
|
||||
const ContactLink = props => <Link to='/contact' {...props} />
|
||||
@@ -52,7 +55,18 @@ class NavBar extends Component {
|
||||
}
|
||||
|
||||
componentDidMount () {
|
||||
const authId = localStorage.getItem('authId')
|
||||
let user = localStorage.getItem('user')
|
||||
|
||||
console.log('componentDidMount user', user)
|
||||
|
||||
let authId
|
||||
|
||||
if (user !== null && user !== undefined && user !== 'undefined') {
|
||||
user = JSON.parse(user)
|
||||
authId = user.authId
|
||||
}
|
||||
|
||||
console.log('componentDidMount authId', authId)
|
||||
|
||||
if (authId !== null && authId !== undefined && authId !== 'undefined') {
|
||||
this.setState({ authId: authId })
|
||||
@@ -106,6 +120,7 @@ class NavBar extends Component {
|
||||
component={UserLink}>
|
||||
<UserIcon />
|
||||
</IconButton>
|
||||
<LoggedInUser authId={this.state.authId} />
|
||||
</Toolbar>
|
||||
</AppBar>
|
||||
</div>
|
||||
|
||||
Reference in new issue
Block a user