Username and user id now show in post data

This commit is contained in:
Aaron Sun 2019-10-27 23:11:24 -04:00
parent 5fa4caf0a3
commit 657277bcad
4 changed files with 51 additions and 59 deletions

View File

@ -1,17 +1,17 @@
/* eslint-disable promise/always-return */
const admin = require('firebase-admin');
exports.putPost = (req, res) => {
exports.putPost = (req, res) => {
const newPost = {
body: req.body.body,
userHandle: req.body.userHandle,
userHandle: req.user.handle,
userImage: req.body.userImage,
userID: req.user.uid,
microBlogTitle: req.body.microBlogTitle,
createdAt: new Date().toISOString(),
likeCount: 0,
commentCount: 0,
microBlogTopics: req.body.microBlogTopics
};
admin.firestore().collection('posts').add(newPost)
@ -27,7 +27,7 @@ exports.putPost = (req, res) => {
};
exports.getallPostsforUser = (req, res) => {
admin.firestore().collection('posts').where('userHandle', '==', 'new user' ).get()
admin.firestore().collection('posts').where('userHandle', '==', req.userData.handle ).get()
.then((data) => {
let posts = [];
data.forEach(function(doc) {

View File

@ -67,7 +67,6 @@ class App extends Component {
<Route exact path="/user" component={user} />
<Route exact path="/home" component={writeMicroblog} />
<Route exact path="/edit" component={editProfile} />
{/* <Route exact path="/user" component={userLine} /> */}
<AuthRoute exact path="/" component={home}/>
</Switch>

View File

@ -33,10 +33,10 @@ class Writing_Microblogs extends Component {
}
handleSubmit(event) {
// alert('A title for the microblog was inputted: ' + this.state.title + '\nA microblog was posted: ' + this.state.value);
const postData = {
body: this.state.value,
userHandle: "new user",
userImage: "bing-url",
microBlogTitle: this.state.title,
microBlogTopics: this.state.topics.split(', ')

View File

@ -1,7 +1,7 @@
/* eslint-disable */
import React, { Component } from 'react';
import { Link } from 'react-router-dom';
// import PropTypes from 'prop-types';
import PropTypes from 'prop-types';
// Material UI stuff
import AppBar from '@material-ui/core/AppBar';
@ -10,70 +10,63 @@ import Button from '@material-ui/core/Button';
import withStyles from "@material-ui/core/styles/withStyles";
// Redux stuff
// import { logoutUser } from '../../redux/actions/userActions';
// import { connect } from 'react-redux';
import { connect } from 'react-redux';
// const styles = {
// form: {
// textAlign: "center"
// },
// textField: {
// marginBottom: 30
// },
// pageTitle: {
// marginBottom: 40
// },
// button: {
// positon: "relative",
// marginBottom: 30
// },
// progress: {
// position: "absolute"
// }
// };
const styles = {
form: {
textAlign: "center"
},
textField: {
marginBottom: 30
},
pageTitle: {
marginBottom: 40
},
button: {
positon: "relative",
marginBottom: 30
},
progress: {
position: "absolute"
}
};
export class Navbar extends Component {
render() {
export class Navbar extends Component {
render() {
const authenticated = this.props.user.authenticated;
return (
<AppBar>
<ToolBar>
<Button component={ Link } to='/'>
Home
</Button>
<Button component={ Link } to='/login'>
{!authenticated && <Button component={ Link } to='/login'>
Login
</Button>
<Button component={ Link } to='/signup'>
</Button>}
{!authenticated && <Button component={ Link } to='/signup'>
Sign Up
</Button>
<Button component={ Link } to='/logout'>
</Button>}
{authenticated && <Button component={ Link } to='/logout'>
Logout
</Button>
<Button component={ Link } to='/delete'>
</Button>}
{authenticated && <Button component={ Link } to='/delete'>
Delete Account
</Button>
</Button>}
</ToolBar>
</AppBar>
)
}
}
// const mapStateToProps = (state) => ({
// user: state.user
// })
const mapStateToProps = (state) => ({
user: state.user
})
// const mapActionsToProps = { logoutUser };
Navbar.propTypes = {
user: PropTypes.object.isRequired,
classes: PropTypes.object.isRequired
}
// Navbar.propTypes = {
// logoutUser: PropTypes.func.isRequired,
// user: PropTypes.object.isRequired,
// classes: PropTypes.object.isRequired
// }
export default connect(mapStateToProps)(withStyles(styles)(Navbar));
// export default connect(mapStateToProps, mapActionsToProps)(withStyles(styles)(Navbar));
export default Navbar;
// export default Navbar;