diff --git a/functions/handlers/users.js b/functions/handlers/users.js
index 21f9b96..00d8f1c 100644
--- a/functions/handlers/users.js
+++ b/functions/handlers/users.js
@@ -50,7 +50,7 @@ exports.signup = (req, res) => {
return res.status(400).json(errors);
}
- let idToken, userId;
+ let token, userId;
db.doc(`/users/${newUser.handle}`)
.get()
@@ -68,8 +68,8 @@ exports.signup = (req, res) => {
userId = data.user.uid;
return data.user.getIdToken();
})
- .then((token) => {
- idToken = token;
+ .then((idToken) => {
+ token = idToken;
const userCred = {
email: req.body.email,
handle: newUser.handle,
@@ -79,7 +79,7 @@ exports.signup = (req, res) => {
return db.doc(`/users/${newUser.handle}`).set(userCred);
})
.then(() => {
- return res.status(201).json({ idToken });
+ return res.status(201).json({ token });
})
.catch((err) => {
console.error(err);
diff --git a/twistter-frontend/src/App.css b/twistter-frontend/src/App.css
index 6c1497d..940f1fc 100644
--- a/twistter-frontend/src/App.css
+++ b/twistter-frontend/src/App.css
@@ -26,7 +26,7 @@ body {
white-space: nowrap;
}
-.register {
+.signup {
background-color: #1da1f2;
border: 1px solid #fff;
color: #fff;
diff --git a/twistter-frontend/src/App.js b/twistter-frontend/src/App.js
index 8e18621..34d4f26 100644
--- a/twistter-frontend/src/App.js
+++ b/twistter-frontend/src/App.js
@@ -1,9 +1,9 @@
/* eslint-disable */
import React, { Component } from "react";
import "./App.css";
+import axios from "axios";
-import { BrowserRouter as Router } from "react-router-dom";
-import Route from "react-router-dom/Route";
+import { BrowserRouter as Router, Route, Switch } from "react-router-dom";
import Navbar from "./components/layout/NavBar";
import jwtDecode from "jwt-decode";
@@ -13,55 +13,67 @@ import store from "./redux/store";
import MuiThemeProvider from '@material-ui/core/styles/MuiThemeProvider';
import createMuiTheme from '@material-ui/core/styles/createMuiTheme';
import themeObject from './util/theme';
-
-// Pages
-import home from './pages/Home';
-import register from './pages/Register';
-import login from './pages/Login';
-import user from './pages/user';
-import writeMicroblog from "./Writing_Microblogs.js";
-import edit from "./pages/edit.js";
-import userLine from "./Userline.js";
+import { SET_AUTHENTICATED } from './redux/types';
+import { logoutUser, getUserData } from './redux/actions/userActions';
// Components
import AuthRoute from "./util/AuthRoute";
-let authenticated;
+// Pages
+import home from './pages/Home';
+import signup from './pages/Signup';
+import login from './pages/Login';
+import user from './pages/user';
+import logout from './pages/Logout';
+import writeMicroblog from './Writing_Microblogs.js';
+import editProfile from './pages/editProfile';
+import userLine from './Userline.js';
+
+const theme = createMuiTheme(themeObject);
+
const token = localStorage.FBIdToken;
if (token) {
const decodedToken = jwtDecode(token);
if (decodedToken.exp * 1000 < Date.now()) {
+ store.dispatch(logoutUser);
window.location.href = "/login";
- authenticated = false;
} else {
- authenticated = true;
+ store.dispatch({ type: SET_AUTHENTICATED });
+ axios.defaults.headers.common['Authorization'] = token;
+ store.dispatch(getUserData());
}
}
-const theme = createMuiTheme(themeObject);
class App extends Component {
render() {
return (
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
-
+
+
+ {/* AuthRoute checks if the user is logged in and if they are it redirects them to /home */}
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
);
}
}
diff --git a/twistter-frontend/src/Logout.js b/twistter-frontend/src/Logout.js
deleted file mode 100644
index db0e002..0000000
--- a/twistter-frontend/src/Logout.js
+++ /dev/null
@@ -1,39 +0,0 @@
-/* eslint-disable */
-import React, { Component} from 'react';
-import './App.css';
-import logo from './images/twistter-logo.png';
-import TextField from '@material-ui/core/TextField';
-import logoutUser from '../redux/actions/userActions.js'
-import { Tooltip, IconButton } from '@material-ui/core';
-import writeMicroblog from './Writing_Microblogs.js';
-import PropTypes from "prop-types";
-
-class Logout extends Component {
- handleLogout = () => {
- localStorage.removeItem("FBIdToken");
- alert("Successfully Logged Out");
- this.props.history.push('/');
- };
- render() {
- return(
-
-

-
-
Logout of your Twistter Account
-
-
-
-
- );
- };
-}
-Logout.protoTypes = {
- classes: PropTypes.object.isRequired,
- logoutUser: PropTypes.object.isRequired
-};
-
-const mapActionsToProps = {
- logoutUser
-}
-
-export default Logout;
diff --git a/twistter-frontend/src/Userline.js b/twistter-frontend/src/Userline.js
index aa75716..8c95620 100644
--- a/twistter-frontend/src/Userline.js
+++ b/twistter-frontend/src/Userline.js
@@ -23,7 +23,7 @@ class Userline extends Component {
componentDidMount() {
- axios.get('http://localhost:5001/twistter-e4649/us-central1/api/getallPostsforUser')
+ axios.get('/getallPostsforUser')
.then(res => {
const post = res.data;
this.setState({microBlogs : post})
diff --git a/twistter-frontend/src/Writing_Microblogs.js b/twistter-frontend/src/Writing_Microblogs.js
index 3bda6cc..b1570d8 100644
--- a/twistter-frontend/src/Writing_Microblogs.js
+++ b/twistter-frontend/src/Writing_Microblogs.js
@@ -34,21 +34,27 @@ 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(', ')
+ }
+ const headers = {
+ headers: { 'Content-Type': 'application/json'}
+ }
- const response = axios.post(
- 'http://localhost:5001/twistter-e4649/us-central1/api/putPost',
- { body: this.state.value,
- userHandle: "new user",
- userImage: "bing-url",
- microBlogTitle: this.state.title,
- microBlogTopics: this.state.topics.split(', ')
-
- },
- { headers: { 'Content-Type': 'application/json'} }
-
- )
- console.log(response.data);
- alert('Post was shared successfully!');
+ axios
+ .post('/putPost', postData, headers)
+ .then((res) =>{
+ alert('Post was shared successfully!')
+ console.log(res.data);
+ })
+ .catch((err) => {
+ alert('An error occured.');
+ console.error(err);
+ })
event.preventDefault();
this.setState({value: '', title: '',characterCount: 250, topics: ''})
}
diff --git a/twistter-frontend/src/components/layout/NavBar.js b/twistter-frontend/src/components/layout/NavBar.js
index 0b6ba22..92ad833 100644
--- a/twistter-frontend/src/components/layout/NavBar.js
+++ b/twistter-frontend/src/components/layout/NavBar.js
@@ -1,12 +1,43 @@
/* eslint-disable */
import React, { Component } from 'react';
import { Link } from 'react-router-dom';
+// import PropTypes from 'prop-types';
+
+// Material UI stuff
import AppBar from '@material-ui/core/AppBar';
import ToolBar from '@material-ui/core/Toolbar';
import Button from '@material-ui/core/Button';
+import withStyles from "@material-ui/core/styles/withStyles";
-export class Navbar extends Component {
- render() {
+// Redux stuff
+// import { logoutUser } from '../../redux/actions/userActions';
+// import { connect } from 'react-redux';
+
+// 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() {
return (
@@ -16,8 +47,8 @@ export class Navbar extends Component {
-