diff --git a/src/components/Logo/index.js b/src/components/Logo/index.js index b4d17c6..6e7f8c0 100644 --- a/src/components/Logo/index.js +++ b/src/components/Logo/index.js @@ -9,10 +9,10 @@ const Logo = ({ color }) => { fill="none" xmlns="http://www.w3.org/2000/svg" > - + diff --git a/src/components/firebase/fire.js b/src/components/firebase/fire.js index c527b59..7744949 100644 --- a/src/components/firebase/fire.js +++ b/src/components/firebase/fire.js @@ -1,5 +1,6 @@ import app from "firebase/app"; import "firebase/auth"; +import "firebase/firestore"; const config = { apiKey: process.env.REACT_APP_FIREBASE_API_KEY, @@ -9,19 +10,16 @@ const config = { storageBucket: process.env.REACT_APP_DEV_STORAGE_BUCKET, messagingSenderId: process.env.REACT_APP_DEV_MESSAGING_SENDER_ID }; -console.log("--------------------"); -console.log(process.env.NODE_ENV); -console.log(process.env.REACT_APP_FIREBASE_API_KEY); -console.log("--------------------"); class Firebase { constructor() { app.initializeApp(config); this.auth = app.auth(); + this.db = app.firestore(); } // Auth - doCreateUserWithEmailAndPassword = (email, password) => + doCreateUserWithEmailAndPassword = (email, password) => this.auth.createUserWithEmailAndPassword(email, password); doSignInWithEmailAndPassword = (email, password) => diff --git a/src/components/screens/Day/Day.js b/src/components/screens/Day/Day.js index 617fa3f..05cdd3f 100644 --- a/src/components/screens/Day/Day.js +++ b/src/components/screens/Day/Day.js @@ -1,6 +1,9 @@ import React, { Component } from "react"; import styled from "@emotion/styled"; +import { compose } from "recompose"; import { withTheme } from "emotion-theming"; +import { withFirebase } from "../../firebase"; +import { withAuthentication } from "../../session"; import { addDays, subDays, format, isAfter, startOfYesterday } from "date-fns"; import { SIZES } from "../../../styles/constants"; @@ -43,11 +46,14 @@ class Day extends Component { const { match: { params: { year, month, day } - } + }, + firebase, + authUser, } = this.props; const currentDay = new Date(year, month - 1, day); console.log(currentDay); if (!currentDay) return; + firebase.db.collection("entries").doc(`${year}${month}${day}-${authUser.uid}`).get().then(doc => console.log(doc.data())) return ( <> @@ -64,4 +70,4 @@ class Day extends Component { } } -export default withTheme(Day); +export default compose(withFirebase,withTheme, withAuthentication)(Day); diff --git a/src/components/screens/Register/Register.js b/src/components/screens/Register/Register.js index 47485c9..204a7ec 100644 --- a/src/components/screens/Register/Register.js +++ b/src/components/screens/Register/Register.js @@ -27,10 +27,11 @@ class RegisterForm extends Component { onSubmit = event => { const { username, email, passwordOne } = this.state; + const { firebase } = this.props - this.props.firebase + firebase .doCreateUserWithEmailAndPassword(email, passwordOne) - .then(authUser => { + .then(result => { this.setState({ username: "", email: "", @@ -38,6 +39,12 @@ class RegisterForm extends Component { passwordTwo: "", error: null }); + const { user } = result + console.log(user) + firebase.db.collection("users").doc(user.uid).set({ + email: user.email, + theme: "LIGHT" + }) this.props.history.push("/home"); }) .catch(error => { @@ -53,7 +60,6 @@ class RegisterForm extends Component { render() { const { username, email, passwordOne, passwordTwo, error } = this.state; - const isInvalid = passwordOne !== passwordTwo || passwordOne === "" || diff --git a/src/components/screens/User/User.js b/src/components/screens/User/User.js index fd1aa4a..9f592e7 100644 --- a/src/components/screens/User/User.js +++ b/src/components/screens/User/User.js @@ -1,5 +1,5 @@ import React from "react"; -import fire from "../../firebase/fire.js"; +import { withFirebase } from "../../firebase"; import SignOut from "../../SignOut"; @@ -16,11 +16,9 @@ class User extends React.Component { addUser = e => { e.preventDefault(); - const db = fire.firestore(); - db.settings({ - timestampsInSnapshots: true - }); - const userRef = db.collection("users").add({ + const { firebase } = this.props + + const userRef = firebase.db.collection("users").doc().add({ name: this.state.name }); this.setState({ name: "" }); @@ -45,4 +43,4 @@ class User extends React.Component { } } -export default User; +export default withFirebase(User); diff --git a/src/components/session/withAuthentication.js b/src/components/session/withAuthentication.js index aa05977..57356f0 100644 --- a/src/components/session/withAuthentication.js +++ b/src/components/session/withAuthentication.js @@ -17,7 +17,13 @@ const withAuthentication = Component => { this.listener = this.props.firebase.auth.onAuthStateChanged( authUser => { localStorage.setItem("authUser", JSON.stringify(authUser)); - this.setState({ authUser }); + this.setState({ + authUser: { + uid: authUser.uid, + email: authUser.email, + emailVerified: authUser.emailVerified, + } + }); }, () => { localStorage.removeItem("authUser"); diff --git a/src/index.css b/src/index.css index 0903b98..134cd0a 100644 --- a/src/index.css +++ b/src/index.css @@ -1,9 +1,6 @@ * { transition: 0.2s all ease-in-out; } -textarea:focus { - outline: none; -} body { margin: 0; padding: 0; diff --git a/src/logo.svg b/src/logo.svg deleted file mode 100644 index 6b60c10..0000000 --- a/src/logo.svg +++ /dev/null @@ -1,7 +0,0 @@ - - - - - - -