/** * Handles a signed in user. Sets the session cookie and then redirects to * profile page on success. * @param {!firebase.User} user */ const handleSignedInUser = function(user) { // Show redirection notice. document.getElementById('redirecting').classList.remove('hidden'); // Set session cookie user.getIdToken().then(function(idToken) { // Session login endpoint is queried and the session cookie is set. // CSRF token should be sent along with request. const csrfToken = getCookie('csrfToken') return postIdTokenToSessionLogin('/sessionLogin', idToken, csrfToken) .then(function() { // Redirect to profile on success. window.location.assign('/profile'); }, function(error) { // Refresh page on error. // In all cases, client side state should be lost due to in-memory // persistence. window.location.assign('/'); }); }); }
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. } })
authRef .currentUser .updatePassword(newPassword) .then(() => { this.setState({ success: true, working: false }); }, error => { this.setState({ error: error.message, working: false }); });
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() .createUserWithEmailAndPassword(email,password) .then(authenticate=>{ return authenticate.user .updateProfile({ displayName: name }) .then(()=>{ this.props.navigation.replace('Home') }) }) .catch(error=>{ alert(error.message) })
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 } }
render() { return ( <GiftedChat messages={this.state.messages} onSend={this.onSend.bind(this)} user={{ _id: this.user.uid, }} /> ); }
firebaseAuth.currentUser.linkAndRetrieveDataWithCredential(credential) .then(() => { this.setState({ showInput: false, buttonText: 'I want to link credentials' }) this.props.navigation.navigate('Login'); ToastAndroid.show('Anonymous account linked with credentials', ToastAndroid.SHORT); }) .catch(error => { this.setState({ errorMessage: error.message }, () => { ToastAndroid.show(this.state.errorMessage, ToastAndroid.SHORT); }) });
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 }); }); }
authRef .currentUser .sendEmailVerification() .then(() => { this.setState({ emailSent: true }); });
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 }; }
authRef .currentUser .updateEmail(newEmail) .then(() => { this.setState({ success: true, working: false }); }, error => { this.setState({ error: error.message, working: false }); });
/** * Handles a signed in user. Sets the session cookie and then redirects to * profile page on success. * @param {!firebase.User} user */ const handleSignedInUser = function(user) { // Show redirection notice. document.getElementById('redirecting').classList.remove('hidden'); // Set session cookie user.getIdToken().then(function(idToken) { // Session login endpoint is queried and the session cookie is set. // CSRF token should be sent along with request. const csrfToken = getCookie('csrfToken') return postIdTokenToSessionLogin('/sessionLogin', idToken, csrfToken) .then(function() { // Redirect to profile on success. window.location.assign('/profile'); }, function(error) { // Refresh page on error. // In all cases, client side state should be lost due to in-memory // persistence. window.location.assign('/'); }); }); }