Skip to content

Commit

Permalink
Version v1.1.3 (#20)
Browse files Browse the repository at this point in the history
* External Auth Providers without scopes now handled (Fixes #18)
* Twitter option added to unit tests to confirm handling of providers without scopes
  • Loading branch information
prescottprue committed Dec 21, 2016
1 parent efbf8be commit 4c3b1d0
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 6 deletions.
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
# react-redux-firebase

[![Gitter][gitter-image]][gitter-url]

[![NPM version][npm-image]][npm-url]
[![NPM downloads][npm-downloads-image]][npm-url]
[![Build Status][travis-image]][travis-url]
[![Dependency Status][daviddm-image]][daviddm-url]
[![Code Coverage][coverage-image]][coverage-url]
[![License][license-image]][license-url]
[![Code Coverage][coverage-image]][coverage-url]
[![Code Style][code-style-image]][code-style-url]
[![Gitter][gitter-image]][gitter-url]

> Redux bindings for Firebase. Includes Higher Order Component (HOC) for use with React.
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "react-redux-firebase",
"version": "1.1.2",
"version": "1.1.3",
"description": "Redux integration for Firebase. Comes with a Higher Order Component for use with React.",
"main": "dist/index.js",
"module": "src/index.js",
Expand Down
11 changes: 10 additions & 1 deletion src/utils/auth.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { capitalize, isArray, isString } from 'lodash'
import { capitalize, isArray, isString, isFunction } from 'lodash'
import { supportedAuthProviders } from '../constants'

/**
Expand All @@ -9,12 +9,20 @@ import { supportedAuthProviders } from '../constants'
*/
export const createAuthProvider = (firebase, providerName, scopes) => {
// TODO: Verify scopes are valid before adding
// TODO: Validate parameter inputs
// Verify providerName is valid
if (supportedAuthProviders.indexOf(providerName.toLowerCase()) === -1) {
throw new Error(`${providerName} is not a valid Auth Provider`)
}
const provider = new firebase.auth[`${capitalize(providerName)}AuthProvider`]()

// Handle providers without scopes
if (providerName.toLowerCase() === 'twitter' || !isFunction(provider.addScope)) {
return provider
}

provider.addScope('email')

if (scopes) {
if (isArray(scopes)) {
scopes.forEach(scope => {
Expand All @@ -25,6 +33,7 @@ export const createAuthProvider = (firebase, providerName, scopes) => {
provider.addScope(scopes)
}
}

return provider
}

Expand Down
10 changes: 8 additions & 2 deletions test/unit/utils/auth.spec.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* global describe expect it beforeEach */
/* global firebase describe expect it */
import {
createAuthProvider,
getLoginMethodAndParams,
getLoginMethodAndParams
} from '../../../src/utils/auth'

describe('Utils: Auth', () => {
Expand All @@ -21,11 +21,17 @@ describe('Utils: Auth', () => {
.to.Throw(Error, `${provider} is not a valid Auth Provider`)
})
})

describe('getLoginMethodAndParams', () => {
it('google provider', () => {
expect(getLoginMethodAndParams(firebase, { provider: 'google' }))
.to.include.keys('method')
})
it('twitter provider', () => {
// TODO: Confirm that addScope
expect(getLoginMethodAndParams(firebase, { provider: 'twitter' }))
.to.include.keys('method')
})
it('token', () => {
expect(getLoginMethodAndParams(firebase, { token: 'asdf' }))
.to.include.keys('method')
Expand Down

0 comments on commit 4c3b1d0

Please sign in to comment.