├── public ├── favicon.ico ├── manifest.json └── index.html ├── src ├── index.js ├── App.test.js ├── index.css ├── Firebase.js ├── components │ ├── Login.js │ ├── Register.js │ └── Dashboard.js ├── logo.svg └── App.js ├── .gitignore ├── package.json └── README.md /public/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bikramkawan/react-firebase-auth-user-todo-list/HEAD/public/favicon.ico -------------------------------------------------------------------------------- /src/index.js: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import ReactDOM from 'react-dom'; 3 | import './index.css'; 4 | import App from './App'; 5 | ReactDOM.render(, document.getElementById('root')); 6 | 7 | -------------------------------------------------------------------------------- /src/App.test.js: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import ReactDOM from 'react-dom'; 3 | import App from './App'; 4 | 5 | it('renders without crashing', () => { 6 | const div = document.createElement('div'); 7 | ReactDOM.render(, div); 8 | }); 9 | -------------------------------------------------------------------------------- /public/manifest.json: -------------------------------------------------------------------------------- 1 | { 2 | "short_name": "React App", 3 | "name": "Create React App Sample", 4 | "icons": [ 5 | { 6 | "src": "favicon.ico", 7 | "sizes": "192x192", 8 | "type": "image/png" 9 | } 10 | ], 11 | "start_url": "./index.html", 12 | "display": "standalone", 13 | "theme_color": "#000000", 14 | "background_color": "#ffffff" 15 | } 16 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # See https://help.github.com/ignore-files/ for more about ignoring files. 2 | 3 | # dependencies 4 | /node_modules 5 | 6 | # testing 7 | /coverage 8 | 9 | /.idea/* 10 | # production 11 | /build 12 | 13 | # misc 14 | .DS_Store 15 | .env.local 16 | .env.development.local 17 | .env.test.local 18 | .env.production.local 19 | 20 | npm-debug.log* 21 | yarn-debug.log* 22 | yarn-error.log* 23 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "firebaseapp", 3 | "version": "0.1.0", 4 | "private": true, 5 | "dependencies": { 6 | "firebase": "^4.3.0", 7 | "react": "^15.6.1", 8 | "react-dom": "^15.6.1", 9 | "react-router-dom": "^4.2.2", 10 | "react-scripts": "1.0.12" 11 | }, 12 | "scripts": { 13 | "start": "react-scripts start", 14 | "build": "react-scripts build", 15 | "test": "react-scripts test --env=jsdom", 16 | "eject": "react-scripts eject" 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/index.css: -------------------------------------------------------------------------------- 1 | body { 2 | margin: 0; 3 | padding: 0; 4 | font-family: sans-serif; 5 | } 6 | 7 | .App { 8 | text-align: center; 9 | } 10 | 11 | .App-logo { 12 | animation: App-logo-spin infinite 20s linear; 13 | height: 80px; 14 | } 15 | 16 | .App-header { 17 | background-color: #222; 18 | height: 150px; 19 | padding: 20px; 20 | color: white; 21 | } 22 | 23 | .App-intro { 24 | font-size: large; 25 | } 26 | 27 | @keyframes App-logo-spin { 28 | from { 29 | transform: rotate(0deg); 30 | } 31 | to { 32 | transform: rotate(360deg); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | #React Firebase Authentication User Based To do List 2 | 3 | This is the example repo for react application using firebase authentication. 4 | 5 | Live preview from here : http://react-firebase-todo.surge.sh/#/ 6 | 7 | ## Features of App 8 | * User can register. 9 | * User can login. 10 | * User can add their own to do list once login. 11 | * Every user has their own dashboard 12 | * User can delete and add wishlist 13 | 14 | ##Instruction 15 | * Update your firebase config in Firebase.js 16 | * Set up : `npm install` 17 | * Start Project: `npm start` 18 | * Deploy : `npm run build` 19 | 20 | -------------------------------------------------------------------------------- /src/Firebase.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Created by bikramkawan on 9/1/17. 3 | */ 4 | import * as firebase from 'firebase'; 5 | 6 | // Initialize Firebase 7 | var config = { 8 | apiKey: "AIzaSyARRzTNYiRVE4DH8CKpM_GoB9bJPFRbIYc", 9 | authDomain: "react-auth-c10ad.firebaseapp.com", 10 | databaseURL: "https://react-auth-c10ad.firebaseio.com", 11 | projectId: "react-auth-c10ad", 12 | storageBucket: "", 13 | messagingSenderId: "154377850617" 14 | }; 15 | export const firebaseApp = firebase.initializeApp(config); 16 | export const users = firebaseApp.database().ref().child('users'); 17 | export const usersWishlist = firebaseApp.database().ref().child('usersWishlist'); -------------------------------------------------------------------------------- /src/components/Login.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Created by bikramkawan on 9/1/17. 3 | */ 4 | import React, {Component} from 'react'; 5 | import {firebaseApp} from '../Firebase' 6 | 7 | class Login extends Component { 8 | 9 | 10 | constructor(props) { 11 | super(props); 12 | this.state = { 13 | email: '', 14 | password: '', 15 | error: { 16 | message: '' 17 | } 18 | } 19 | } 20 | 21 | login = ()=> { 22 | 23 | const {email, password} = this.state; 24 | firebaseApp.auth().signInWithEmailAndPassword(email, password) 25 | .catch(error=> this.setState({error})) 26 | } 27 | render() { 28 | return ( 29 |
30 |
31 | this.setState({email: target.value})} 36 | /> 37 | this.setState({password: target.value})} 42 | /> 43 | 44 | 45 | 46 | 47 |
48 |
49 | 50 | 51 | ) 52 | 53 | 54 | } 55 | 56 | 57 | } 58 | 59 | export default Login; -------------------------------------------------------------------------------- /public/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 11 | 12 | 13 | 14 | 15 | 24 | React App 25 | 26 | 27 | 30 |
31 | 41 | 42 | 43 | -------------------------------------------------------------------------------- /src/components/Register.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Created by bikramkawan on 9/1/17. 3 | */ 4 | import React, {Component} from 'react'; 5 | import {firebaseApp,users} from '../Firebase' 6 | 7 | class Register extends Component { 8 | 9 | 10 | constructor(props) { 11 | super(props); 12 | this.state = { 13 | email: '', 14 | password: '', 15 | error: { 16 | message: '' 17 | } 18 | } 19 | } 20 | 21 | 22 | register = ()=> { 23 | console.log(this.state); 24 | const {email, password} = this.state; 25 | firebaseApp.auth().createUserWithEmailAndPassword(email, password) 26 | .then((user)=> { 27 | console.log(user) 28 | const thisUser = users.child(user.uid); 29 | const userdetail = thisUser.child('userdetail'); 30 | const dataToInsert = {email: user.email, userid: user.uid}; 31 | userdetail.set(dataToInsert) 32 | }) 33 | .catch(error=> this.setState({error})) 34 | 35 | 36 | } 37 | 38 | 39 | render() { 40 | return ( 41 |
42 |
43 | this.setState({email: target.value})} 48 | /> 49 | this.setState({password: target.value})} 54 | /> 55 | 56 | 63 | 64 |
{this.state.error.message}
65 | 66 |
67 |
68 | 69 | 70 | ) 71 | 72 | 73 | } 74 | 75 | 76 | } 77 | 78 | export default Register ; -------------------------------------------------------------------------------- /src/logo.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /src/components/Dashboard.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Created by bikramkawan on 9/1/17. 3 | */ 4 | import React, {Component} from 'react'; 5 | import {usersWishlist} from '../Firebase' 6 | 7 | class Dashboard extends Component { 8 | 9 | constructor(props) { 10 | super(props); 11 | this.state = { 12 | wishlist: '', 13 | completeWishlist: [] 14 | } 15 | 16 | } 17 | 18 | removeWishlist = (index) => { 19 | const {userid} = this.props; 20 | const thisUser = usersWishlist.child(userid); 21 | let completeWishlist = this.state.completeWishlist.slice(); 22 | completeWishlist.splice(index,1) 23 | this.setState({completeWishlist: completeWishlist}) 24 | thisUser.set({completeWishlist}); 25 | 26 | } 27 | 28 | addWishlist = ()=> { 29 | const {userid} = this.props; 30 | const thisUser = usersWishlist.child(userid); 31 | const {wishlist} = this.state; 32 | const {completeWishlist} = this.state; 33 | completeWishlist.push(wishlist); 34 | this.setState({completeWishlist: completeWishlist}) 35 | thisUser.set({completeWishlist}); 36 | 37 | } 38 | 39 | 40 | componentDidMount() { 41 | const {userid} = this.props; 42 | const thisUser = usersWishlist.child(userid); 43 | thisUser.on('value', (snap, i)=> { 44 | snap.forEach((d, i)=> this.setState({completeWishlist: d.val()})) 45 | 46 | }) 47 | 48 | } 49 | 50 | renderWishlist() { 51 | return this.state.completeWishlist.map((item, index)=> { 52 | return ( 53 |
  • {item} 54 | 57 | 58 |
  • 59 | ) 60 | }) 61 | 62 | } 63 | 64 | 65 | render() { 66 | console.log(this.state) 67 | return ( 68 | 69 |
    70 |
    71 |
    72 |
    73 | this.setState({wishlist: target.value})} 76 | /> 77 | 82 |
    83 |
    84 |
    85 |
      86 | {this.renderWishlist()} 87 | 88 |
    89 |
    90 |
    91 | 92 |
    93 | 94 | 95 | ) 96 | 97 | 98 | } 99 | 100 | 101 | } 102 | 103 | export default Dashboard; -------------------------------------------------------------------------------- /src/App.js: -------------------------------------------------------------------------------- 1 | import React, {Component} from 'react'; 2 | import logo from './logo.svg'; 3 | import {HashRouter, Route, Link, Redirect} from 'react-router-dom'; 4 | import Login from './components/Login' 5 | import Register from './components/Register' 6 | import {firebaseApp} from './Firebase'; 7 | import Dashboard from './components/Dashboard' 8 | 9 | class App extends Component { 10 | 11 | constructor() { 12 | super(); 13 | this.state = { 14 | authed: false, 15 | userid: null, 16 | email: null 17 | } 18 | } 19 | 20 | 21 | componentDidMount() { 22 | this.removeFirebaseEvent = firebaseApp.auth().onAuthStateChanged((user) => { 23 | if (user) { 24 | this.setState({authed: true, userid: user.uid, email: user.email}) 25 | 26 | 27 | } else { 28 | this.setState({ 29 | authed: false, 30 | }) 31 | } 32 | }) 33 | 34 | } 35 | 36 | 37 | logout = ()=> { 38 | firebaseApp.auth().signOut(); 39 | } 40 | 41 | componentWillUnmount() { 42 | this.removeFirebaseEvent() 43 | } 44 | 45 | render() { 46 | return ( 47 | 48 |
    49 |
    50 | logo 51 |

    React Firebase Authentication User Based Todo List

    52 |
    53 | 54 | 75 | {!this.state.authed ?

    Please login if you are existing user.

    76 |
    77 |

    Please register if you are not registered to use the app.

    78 |
    : ''} 79 |
    80 | this.state.authed ? :
    }/> 81 | this.state.authed ? : }/> 82 | this.state.authed ? 84 | : 85 | }/> 86 | 87 |
    88 | 89 |
    90 |
    91 | ); 92 | } 93 | } 94 | 95 | export default App; 96 | --------------------------------------------------------------------------------