React-redux-firebase: Expose unsupported methods

Created on 26 Jan 2017  路  4Comments  路  Source: prescottprue/react-redux-firebase

Hi!

Is there a way to expose firebase methods which are not supported by the framework? For example, I would like to use the method sendPasswordResetEmail. If yes, what would be the best way to achieve it?

Thanks in advance

question

Most helpful comment

Just to confirm - this.props.firebase.sendPasswordResetEmail() doesn't work?

If that does not work, you can always import raw firebase object and use that for any not supported functionality:

import { getFirebase } from 'react-redux-firebase'

getFirebase().auth().sendPasswordResetEmail()

All 4 comments

Just to confirm - this.props.firebase.sendPasswordResetEmail() doesn't work?

If that does not work, you can always import raw firebase object and use that for any not supported functionality:

import { getFirebase } from 'react-redux-firebase'

getFirebase().auth().sendPasswordResetEmail()

@katha247 there is full access to Firebase's auth through firebase.auth including sendPasswordResetEmail

An example component could use it like so:

import React, { Component, PropTypes } from 'react';
import { connect } from 'react-redux';
import { firebaseConnect, helpers } from 'react-redux-firebase';

const { isLoaded, isEmpty, pathToJS } = helpers;

@firebaseConnect()
export default class Login extends Component {
  static propTypes = {
    firebase: PropTypes.shape({
      auth: PropTypes.func.isRequired,
    }),
  }

  sendResetEmail = () => {
    this.props.firebase.auth()
      .sendPasswordResetEmail()
      .then(() => {
         console.log('email sent successfully');
      })
      .catch((err) => {
          console.error('Error sending password reset email:', err)
       })
  }

  render() {
    return (
      <div>
        <button onClick={this.sendResetEmail}>Send Reset Email</button>
      </div>
    );
  }
}

You can also it get access to it in thunk actions using getFirebase.

The goal is to eventually support most main methods at a top level. It should be easy enough to expose this function in the future for ease of use.

Thanks for your responses, I got it to work!

@DeividasK: this.props.firebase.sendPasswordResetEmail() does not work, but when using firebase.auth() it works fine. No need to import the raw firebase object.

@prescottprue: I used your suggestion: this.props.firebase.auth().sendPasswordResetEmail()

@katha247 I will update this issue (even though it will be closed) if the sendPasswordResetEmail is exposed as a top level method (i.e. this.props.firebase.sendPasswordResetEmail).

Was this page helpful?
0 / 5 - 0 ratings