Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Docs update for login method credential support.
* deprecation warning added for provider + token combo in login method
  • Loading branch information
Scott Prue committed Jul 10, 2017
commit 21fa7f60fe73b60d2f577ea27978fe583b2d211f
2 changes: 1 addition & 1 deletion bin/api-docs-generate.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const exec = require('child_process').exec
const files = [
{
src: 'connect.js',
src: 'firebaseConnect.js',
dest: 'connect.md'
},
{
Expand Down
64 changes: 56 additions & 8 deletions docs/api/compose.md
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,8 @@ Sets data to Firebase.
_Basic_

```javascript
import React, { Component, PropTypes } from 'react'
import React, { Component } from 'react'
import PropTypes from 'prop-types'
import { firebaseConnect } from 'react-redux-firebase'
const Example = ({ firebase: { set } }) => (
<button onClick={() => set('some/path', { here: 'is a value' })}>
Expand Down Expand Up @@ -144,7 +145,8 @@ Pushes data to Firebase.
_Basic_

```javascript
import React, { Component, PropTypes } from 'react'
import React, { Component } from 'react'
import PropTypes from 'prop-types'
import { firebaseConnect } from 'react-redux-firebase'
const Example = ({ firebase: { push } }) => (
<button onClick={() => push('some/path', true)}>
Expand Down Expand Up @@ -184,7 +186,8 @@ Updates data on Firebase and sends new data.
_Basic_

```javascript
import React, { Component, PropTypes } from 'react'
import React, { Component } from 'react'
import PropTypes from 'prop-types'
import { firebaseConnect } from 'react-redux-firebase'
const Example = ({ firebase: { update } }) => (
<button onClick={() => update('some/path', { here: 'is a value' })}>
Expand Down Expand Up @@ -224,7 +227,8 @@ Removes data from Firebase at a given path.
_Basic_

```javascript
import React, { Component, PropTypes } from 'react'
import React, { Component } from 'react'
import PropTypes from 'prop-types'
import { firebaseConnect } from 'react-redux-firebase'
const Example = ({ firebase: { remove } }) => (
<button onClick={() => remove('some/path')}>
Expand Down Expand Up @@ -252,7 +256,8 @@ exist, otherwise it rejects.
_Basic_

```javascript
import React, { Component, PropTypes } from 'react'
import React, { Component } from 'react'
import PropTypes from 'prop-types'
import { firebaseConnect } from 'react-redux-firebase'
const Example = ({ firebase: { uniqueSet } }) => (
<button onClick={() => uniqueSet('some/unique/path', true)}>
Expand Down Expand Up @@ -402,12 +407,55 @@ email is valid

Returns **[Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise)** Containing user auth info

# updateProfile

Update the currently logged in user's profile object

**Parameters**

- `profileUpdate` **[String](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)** Changes to apply to profile
- `profile`

Returns **[Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise)**

# updateAuth

Update the currently logged in user's auth object. **Note**:
changes Auth object **only**, not user's profile.

**Parameters**

- `code` **[String](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)** Password reset code to verify
- `authUpdate`

Returns **[Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise)**

# updateEmail

Update the currently logged in user's email. **Note**:
changes email in Auth object only, not within user's profile.

**Parameters**

- `newEmail` **[String](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)** New email
- `email`
- `updateInProfile` **[Boolean](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean)** Whether or not to update user's
profile with email change.

Returns **[Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise)**

# ref

Firebase ref function

Returns **database.Reference**

# auth

Firebase auth service instance including all Firebase auth methods

Returns **Auth**

# database

Firebase database service instance including all Firebase storage methods
Expand All @@ -420,11 +468,11 @@ Firebase storage service instance including all Firebase storage methods

Returns **Storage** Firebase storage service

# auth
# messaging

Firebase auth service instance including all Firebase auth methods
Firebase messaging service instance including all Firebase messaging methods

Returns **Auth**
Returns **Messaging** Firebase messaging service

# getFirebase

Expand Down
54 changes: 37 additions & 17 deletions docs/auth.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,22 +58,29 @@ export default firebaseConnect()(SomeComponent)
* email and password (runs `ref.authWithPassword(credentials)`) :
```js
{
email: String
password: String
email: String,
password: String
}
```
* provider (runs `ref.authWithOAuthPopup(provider)` or `ref.authWithOAuthRedirect(provider)`) :
```js
{
provider: "facebook | google | twitter",
type: "popup | redirect", // popup is default
provider: "facebook | google | twitter",
type: "popup | redirect" // popup is default
}
```
* provider and token (runs `ref.authWithOAuthToken(provider, token)`) :
* credential (runs `ref.signInWithCredential(credential)`) :
```js
{
provider: "facebook | google | twitter",
token : String
credential : firebase.auth.AuthCredential // created using specific provider
}
```
The credential parameter is a firebase.auth.AuthCredential specific to the provider (i.e. `firebase.auth.GoogleAuthProvider.credential(null, 'some accessToken')`). For more details [please view the Firebase API reference](https://firebase.google.com/docs/reference/js/firebase.auth.GoogleAuthProvider#methods)
* provider and token (runs `ref.authWithOAuthToken(provider, token)`) **NOTE**: *Deprecated as of v1.5.0* :
```js
{
provider: "facebook | google | twitter",
token : String
}
```

Expand All @@ -83,9 +90,8 @@ export default firebaseConnect()(SomeComponent)

##### Examples

*Email*
*Email*
```js
// Call with info
this.props.firebase.login({
email: '[email protected]',
password: 'testest1'
Expand All @@ -94,32 +100,43 @@ this.props.firebase.login({

*OAuth Provider Redirect*
```js
// Call with info
this.props.firebase.login({
provider: 'google',
type: 'redirect'
})
this.props.firebase.login({
provider: 'google',
type: 'redirect'
})
```

*OAuth Provider Popup*
*OAuth Provider Popup*
```js
// Call with info
this.props.firebase.login({
provider: 'google',
type: 'popup'
})
```

*Credential*
```js
// `googleUser` from the onsuccess Google Sign In callback.
this.props.firebase.login({
credential: firebase.auth.GoogleAuthProvider.credential(googleUser.getAuthResponse().id_token)
})
// or using an accessToken
this.props.firebase.login({
credential: firebase.auth.GoogleAuthProvider.credential(null, 'some access token')
})
```

*Token*
```js
// Call with info
this.props.firebase.login('someJWTAuthToken')
```

## createUser(credentials, profile)

Similar to Firebase's `ref.createUser(credentials)` but with support for automatic profile setup (based on your userProfile config).

**NOTE** This does not need to be used when using external authentication providers (Firebase creates the user automatically), and is meant to be used with email authentication only.

##### Parameters

* `credentials` [**Object**](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)
Expand Down Expand Up @@ -153,6 +170,9 @@ createNewUser({
## logout()
Logout from Firebase and delete all data from the store (`state.firebase.data` and `state.firebase.auth` are set to `null`).


Looking to preserve data on logout? [`v2.0.0` supports the `preserve` config option](http://docs.react-redux-firebase.com/history/v2.0.0/docs/api/compose.html), which preserves data under the specified keys in state on logout.

##### Examples

```js
Expand Down
2 changes: 2 additions & 0 deletions src/actions/auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,8 @@ export const init = (dispatch, firebase) => {
* @param {Object} credentials.provider - Provider name such as google, twitter (only needed for 3rd party provider login)
* @param {Object} credentials.type - Popup or redirect (only needed for 3rd party provider login)
* @param {Object} credentials.token - Custom or provider token
* @param {firebase.auth.AuthCredential} credentials.credential - Custom or provider token
* @param {Array|String} credentials.scopes - Scopes to add to provider (i.e. email)
* @return {Promise}
* @private
*/
Expand Down
7 changes: 4 additions & 3 deletions src/utils/auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,12 @@ export const createAuthProvider = (firebase, providerName, scopes) => {
* @private
*/
export const getLoginMethodAndParams = (firebase, {email, password, provider, type, token, scopes, credential}) => {
if (credential) {
return { method: 'signInWithCredential', params: [ credential ] }
}
if (provider) {
if (credential) {
return { method: 'signInWithCredential', params: [ credential ] }
}
if (token) {
console.warn('Provider + Token combination is deprecated and will be removed from the next major version. Use credential parameter.') // eslint-disable-line no-console
return { method: 'signInWithCredential', params: [ provider, token ] }
}
const authProvider = createAuthProvider(firebase, provider, scopes)
Expand Down