firebaseApp.auth().onAuthStateChanged(user => { if (user) { const { currentUser } = firebaseApp.auth(); console.log('Currently logged in user', currentUser); store.dispatch(userLoggedIn(currentUser.uid)); browserHistory.push('/newsfeed'); // save the current user's uid to redux store. } else { browserHistory.push('/signin'); // delete the current user's uid from the redux store. } })
render() { return ( <GiftedChat messages={this.state.messages} onSend={this.onSend.bind(this)} user={{ _id: this.user.uid, }} /> ); }
const fetchEmployees = () => { const {currentUser} = firebase.auth(); return (dispatch) => { firebase.database().ref(`/users/${currentUser.uid}/employees`) .on('value', (snapshot) => { dispatch({type: FETCH_EMPLOYEE_SUCCESS, payload: snapshot.val()}) }); //TODO catch error } }
constructor( private afs: AngularFirestore, private authService: AuthService ) { this.authService.getAuthState() .subscribe((user) => { if (user) { // User is signed in. this.userId = user.uid; this.username = user.email; } else { this.userId = undefined; } }); }
const createEmployee = ({name, phone, shift}) => { const {currentUser} = firebase.auth(); return (dispatch) => { firebase.database().ref(`/users/${currentUser.uid}/employees`) .push({name, phone, shift}) .then(() => { dispatch({type: CREATE_EMPLOYEE}); Actions.employeeList({type: 'reset'}) }); //TODO catch error } }
onSend(messages = []) { // this.setState({ // messages: GiftedChat.append(this.state.messages, messages), // }); messages.forEach(message => { var now = new Date().getTime() this.chatRef.push({ _id: now, text: message.text, createdAt: now, uid: this.user.uid, order: -1 * now }) }) }
// ON USER, FETCH DATA AND RENDER firebase.auth().onAuthStateChanged( async (user) => { console.log(user.uid); let data = await getBatch(); if(data.success == false) { return alert('MNIST data could not be fetched.'); } document.querySelector('.loader').classList.add('hidden'); ReactDOM.render( <Page batch={data.batch} />, document.getElementById('root') ); });
componentDidMount() { /* Observable from RxFire */ loggedIn$.subscribe(user => { this.authHandler({ user }); //Update state on load of app const { displayName, email, phoneNumber, photoURL } = user; firestore .collection('users') .doc(user.uid) .set({ displayName, email, phoneNumber, photoURL }); }); }
firebase.auth().onAuthStateChanged((user) => { if (user) { store.dispatch(login(user.uid)); store.dispatch(startSetExpenses()).then(() => { renderApp(); if (history.location.pathname === '/') { history.push('/dashboard'); } }); } else { store.dispatch(logout()); renderApp(); history.push('/'); } });
checkLogin(){ firebase.auth().onAuthStateChanged((user)=> { if (user) { this.setState( {user:user} ) this.getPhotos(user.uid) this.props.history.push("/add"); } else { // No user is signed in. } }); }
async componentDidMount() { try { // Get User Credentials let user = await firebase.auth().currentUser; // Listen for Mobile Changes Database.listenUserMobile(user.uid, (mobileNumber) => { this.setState({ mobile: mobileNumber, mobileForm: mobileNumber }); }); this.setState({ uid: user.uid }); } catch (error) { console.log(error); } }
const deleteEmployee = ({uid}) => { const {currentUser} = firebase.auth(); return () => { firebase.database().ref(`/users/${currentUser.uid}/employees/${uid}`) .remove() .then(() => { Actions.employeeList({type: 'reset'}); }); //TODO catch error }; }
const saveEmployee = ({name, phone, shift, uid}) => { const {currentUser} = firebase.auth(); return (dispatch) => { firebase.database().ref(`/users/${currentUser.uid}/employees/${uid}`) .set({name, phone, shift}) .then(() => { dispatch({type: SAVE_EMPLOYEE_SUCCESS}); Actions.employeeList({type: 'reset'}); }); //TODO catch error } }
firebase.auth().onAuthStateChanged((user) => { if(user) { store.dispatch(login(user.uid)); // Load up store.dispatch(startSetExpenses()).then(() => { renderApp(); if(history.location.pathname === '/'){ history.push('/dashboard'); } }); } else { store.dispatch(logout()); renderApp(); history.push('/'); } });