async logout() { try { await firebase.auth().signOut(); this.props.navigator.push({ name: "Login" }) } catch (error) { console.log(error); } }
SignIn(){ console.log('state',this.state); const {email,password} = this.state; firebaseApp.auth().signInWithEmailAndPassword(email,password) .catch(error => { console.log('error',error); this.setState({error}) }) }
signUp() { const { email, password } = this.state; firebaseApp.auth().createUserWithEmailAndPassword(email, password) .catch(error => { this.setState({error}); }) }
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. } })
function handleClickHome() { const { currentUser } = firebaseApp.auth(); console.log(currentUser); if (currentUser) { browserHistory.push('/newsfeed'); } else { browserHistory.push('/welcome'); } }
signIn() { const { email, password } = this.state; firebaseApp.auth().signInWithEmailAndPassword(email, password) .then(this.props.history.push('/app')) .catch(error => { this.setState({error}); }) }
const startLogin = () =>{ return () =>{ return firebase.auth().signInWithPopup(googleAuthProvider); }; }
sendMessage() { console.log("send message triggered"); const { message } = this.state; const { currentUser } = firebaseApp.auth(); messageRef.push({ message: message, author: currentUser.email }); }
firebaseApp.auth().onAuthStateChanged(user => { if(user) { const { email } = user; store.dispatch(logUser(email)); history.push('/app'); } else { history.push('/signin'); } })
signIn() { const { email, password } = this.state; firebaseApp.auth().signInWithEmailAndPassword(email, password) .then(() => { this.setState({isLoggedIn: true}); browserHistory.push('/newsfeed'); }) .catch(error => { this.setState({ error }); }) }
constructor(props) { super(props); this.state = { user: null } firebase.auth().onAuthStateChanged(user => { if (user) { this.setState({ user }); console.log('logged in'); } else { this.setState({ user: null }); console.log('logged out'); } }); }
const startLogout = () => { return () => { return firebase.auth().signOut(); }; }
SignUp(){ console.log('state',this.state); const {email,password} = this.state; firebaseApp.auth().createUserWithEmailAndPassword(email,password) .catch(error => { console.log('error',error); this.setState({error}) }) }
const startLogin = () => { return () => { return firebase.auth().signInWithPopup(googleAuthProvider); }; }
const startLogout = () => { return () => { return firebase.auth().signOut(); } }