The Road to React with Firebase by Robin Wieruch
Author:Robin Wieruch [Robin Wieruch]
Language: eng
Format: epub
Publisher: leanpub.com
Published: 2017-12-12T00:00:00+00:00
We don’t want to grant any user the power to sign up as admin, but we’ll keep it simple for now, and you can decide which circumstances prompt you to assign roles to users later. Next, add the roles property to your user when they are created in the database. Since we need an object of roles, we’ll initialize it as an empty object and add conditional roles to it:
src/components/SignUp/index.js import React, { Component } from 'react'; import { Link, withRouter } from 'react-router-dom'; import { compose } from 'recompose'; import { withFirebase } from '../Firebase'; import * as ROUTES from '../../constants/routes'; import * as ROLES from '../../constants/roles'; ... class SignUpFormBase extends Component { ... onSubmit = event => { const { username, email, passwordOne, isAdmin } = this.state; const roles = {}; if (isAdmin) { roles[ROLES.ADMIN] = ROLES.ADMIN; } this.props.firebase .doCreateUserWithEmailAndPassword(email, passwordOne) .then(authUser => { // Create a user in your Firebase realtime database return this.props.firebase .user(authUser.user.uid) .set({ username, email, roles, }) }) .then(() => { this.setState({ ...INITIAL_STATE }); this.props.history.push(ROUTES.HOME); }) .catch(error => { this.setState({ error }); }); event.preventDefault(); }; ... } ...
Download
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.
Coding Theory | Localization |
Logic | Object-Oriented Design |
Performance Optimization | Quality Control |
Reengineering | Robohelp |
Software Development | Software Reuse |
Structured Design | Testing |
Tools | UML |
Deep Learning with Python by François Chollet(12569)
Hello! Python by Anthony Briggs(9914)
OCA Java SE 8 Programmer I Certification Guide by Mala Gupta(9795)
The Mikado Method by Ola Ellnestam Daniel Brolund(9777)
Dependency Injection in .NET by Mark Seemann(9337)
Algorithms of the Intelligent Web by Haralambos Marmanis;Dmitry Babenko(8296)
Test-Driven iOS Development with Swift 4 by Dominik Hauser(7763)
Grails in Action by Glen Smith Peter Ledbrook(7696)
The Well-Grounded Java Developer by Benjamin J. Evans Martijn Verburg(7557)
Becoming a Dynamics 365 Finance and Supply Chain Solution Architect by Brent Dawson(7064)
Microservices with Go by Alexander Shuiskov(6825)
Practical Design Patterns for Java Developers by Miroslav Wengner(6744)
Test Automation Engineering Handbook by Manikandan Sambamurthy(6688)
Secrets of the JavaScript Ninja by John Resig Bear Bibeault(6413)
Angular Projects - Third Edition by Aristeidis Bampakos(6092)
The Art of Crafting User Stories by The Art of Crafting User Stories(5617)
NetSuite for Consultants - Second Edition by Peter Ries(5556)
Demystifying Cryptography with OpenSSL 3.0 by Alexei Khlebnikov(5360)
Kotlin in Action by Dmitry Jemerov(5062)
