Skip to content

Commit 91c2bd9

Browse files
authored
Version v1.3.2 (prescottprue#75)
### Enhancements * `confirmPasswordReset` action added from prescottprue#74 (thanks @rpeterson) * `verifyPasswordResetCode` action added * If no profile is passed to `firebase.createUser`, email is used by default * Docs updated with new methods * Tests added for new auth actions
1 parent 526eb10 commit 91c2bd9

File tree

6 files changed

+136
-23
lines changed

6 files changed

+136
-23
lines changed

.travis.yml

+1-2
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ addons:
2222
repo_token: $CODE_CLIMATE
2323

2424
before_install:
25-
- "npm install react firebase lodash redux react-redux"
25+
- "npm install react redux react-redux"
2626

2727
after_success:
2828
- npm install -g codeclimate-test-reporter
@@ -35,5 +35,4 @@ deploy:
3535
email: $NPM_EMAIL
3636
api_key: $NPM_TOKEN
3737
on:
38-
tags: true
3938
branch: master

docs/auth.md

+35-1
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,7 @@ Similar to Firebase's `ref.createUser(credentials)` but with support for automat
125125
* `credentials` [**Object**](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)
126126
* `credentials.email` [**String**](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String) - User's email
127127
* `credentials.password` [**String**](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String) - User's password
128+
* `credentials.signIn` [**String**](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String) - Whether or not to sign in when user is signing up (defaults to `true`)
128129

129130
* `profile` [**Object**](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)
130131
* `profile.username` [**String**](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)
@@ -160,7 +161,7 @@ firebase.logout()
160161
```
161162

162163
## resetPassword(credentials)
163-
Calls Firebase's `ref.resetPassword(credentials)` then adds the output into redux state under `state.firebase.authError`
164+
Calls Firebase's `firebase.auth().resetPassword()`. If there is an error, it is added into redux state under `state.firebase.authError`, which can be loaded using `pathToJS(state.firebase, 'authError')`.
164165
165166
##### Examples
166167
@@ -179,3 +180,36 @@ firebase.resetPassword({
179180
##### Returns
180181
[**Promise**](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise) with user's UID in case of success or the error otherwise.
181182
Always authenticate the new user in case of success
183+
184+
## confirmPasswordReset(code, newPassword)
185+
Calls Firebase's `firebase.auth().confirmPasswordReset()`. If there is an error, it is added into redux state under `state.firebase.authError`, which can be loaded using `pathToJS(state.firebase, 'authError')`.
186+
187+
##### Examples
188+
189+
```js
190+
firebase.confirmPasswordReset('some reset code', 'myNewPassword')
191+
```
192+
193+
##### Parameters
194+
* `code` [**String**](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object) - Password reset code
195+
* `newPassword` [**String**](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object) - New password to set for user
196+
197+
##### Returns
198+
[**Promise**](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise)
199+
200+
## verifyPasswordResetCode(code)
201+
Verify a password reset code from password reset email.
202+
203+
Calls Firebase's `firebase.auth().verifyPasswordResetCode()`. If there is an error, it is added into redux state under `state.firebase.authError`, which can be loaded using `pathToJS(state.firebase, 'authError')`.
204+
205+
##### Examples
206+
207+
```js
208+
firebase.verifyPasswordResetCode('some reset code')
209+
```
210+
211+
##### Parameters
212+
* `code` [**String**](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object) - Password reset code
213+
214+
##### Returns
215+
[**Promise**](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise) - Email associated with reset code

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "react-redux-firebase",
3-
"version": "1.3.1",
3+
"version": "1.3.2",
44
"description": "Redux integration for Firebase. Comes with a Higher Order Component for use with React.",
55
"browser": "dist/react-redux-firebase.js",
66
"main": "lib/index.js",

src/actions/auth.js

+26-4
Original file line numberDiff line numberDiff line change
@@ -338,11 +338,13 @@ export const createUser = (dispatch, firebase, { email, password, signIn }, prof
338338
return firebase.auth()
339339
.createUserWithEmailAndPassword(email, password)
340340
.then((userData) =>
341-
// Login to newly created account if signIn flag is true
341+
// Login to newly created account if signIn flag is not set to false
342342
firebase.auth().currentUser || (!!signIn && signIn === false)
343-
? createUserProfile(dispatch, firebase, userData, profile)
343+
? createUserProfile(dispatch, firebase, userData, profile || { email })
344344
: login(dispatch, firebase, { email, password })
345-
.then(() => createUserProfile(dispatch, firebase, userData, profile || { email }))
345+
.then(() =>
346+
createUserProfile(dispatch, firebase, userData, profile || { email })
347+
)
346348
.catch(err => {
347349
if (err) {
348350
switch (err.code) {
@@ -427,6 +429,25 @@ export const confirmPasswordReset = (dispatch, firebase, code, password) => {
427429
})
428430
}
429431

432+
/**
433+
* @description Verify that password reset code is valid
434+
* @param {Function} dispatch - Action dispatch function
435+
* @param {Object} firebase - Internal firebase object
436+
* @param {String} code - Password reset code
437+
* @return {Promise} email - Email associated with reset code
438+
* @private
439+
*/
440+
export const verifyPasswordResetCode = (dispatch, firebase, code) => {
441+
dispatchLoginError(dispatch, null)
442+
return firebase.auth()
443+
.verifyPasswordResetCode(code)
444+
.catch((err) => {
445+
if (err) {
446+
dispatchLoginError(dispatch, err)
447+
}
448+
return Promise.reject(err)
449+
})
450+
}
430451

431452
export default {
432453
dispatchLoginError,
@@ -440,5 +461,6 @@ export default {
440461
logout,
441462
createUser,
442463
resetPassword,
443-
confirmPasswordReset
464+
confirmPasswordReset,
465+
verifyPasswordResetCode
444466
}

src/compose.js

+4
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,9 @@ export default (fbConfig, otherConfig) => next =>
144144
const confirmPasswordReset = (code, password) =>
145145
authActions.confirmPasswordReset(dispatch, firebase, code, password)
146146

147+
const verifyPasswordResetCode = (code) =>
148+
authActions.verifyPasswordResetCode(dispatch, firebase, code)
149+
147150
firebase.helpers = {
148151
ref: path => Firebase.database().ref(path),
149152
set,
@@ -159,6 +162,7 @@ export default (fbConfig, otherConfig) => next =>
159162
createUser,
160163
resetPassword,
161164
confirmPasswordReset,
165+
verifyPasswordResetCode,
162166
watchEvent,
163167
unWatchEvent,
164168
storage: () => Firebase.storage()

tests/unit/actions/auth.spec.js

+69-15
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import {
1212
createUser,
1313
resetPassword,
1414
confirmPasswordReset,
15+
verifyPasswordResetCode,
1516
} from '../../../src/actions/auth'
1617
import { promisesForPopulate } from '../../../src/utils/populate'
1718

@@ -74,7 +75,10 @@ const fakeFirebase = {
7475
confirmPasswordReset: (code, password) =>
7576
password === 'error'
7677
? Promise.reject({code: code})
77-
: Promise.resolve()
78+
: Promise.resolve(),
79+
verifyPasswordResetCode: (code) => code === 'error'
80+
? Promise.reject({ code: 'some' })
81+
: Promise.resolve('success')
7882
})
7983
}
8084

@@ -171,25 +175,24 @@ describe('Actions: Auth', () => {
171175
})
172176

173177
describe('login', () => {
174-
it('handles invalid email login', () => {
175-
return login(dispatch, firebase, fakeLogin)
178+
it('handles invalid email login', () =>
179+
login(dispatch, firebase, fakeLogin)
176180
.catch((err) => {
177181
expect(err.code).to.equal('auth/user-not-found')
178182
})
179-
}, 4000)
180-
it('handles invalid token login', () => {
181-
return login(dispatch, firebase, { token: 'test@tst.com' })
183+
, 4000)
184+
it('handles invalid token login', () =>
185+
login(dispatch, firebase, { token: 'test@tst.com' })
182186
.catch((err) => {
183187
expect(err.code).to.equal('auth/invalid-custom-token')
184188
})
185-
}, 4000)
186-
it('handles token login', () => {
187-
const token = 'asdfasdf'
188-
return login(dispatch, fakeFirebase, { token }, { uid: 'asdfasdf' })
189+
, 4000)
190+
it('handles token login', () =>
191+
login(dispatch, fakeFirebase, { token: 'asdfasdf' }, { uid: 'asdfasdf' })
189192
.then((authData) => {
190193
expect(authData).to.be.an.object
191194
})
192-
}, 4000)
195+
, 4000)
193196
})
194197

195198
describe('logout', () => {
@@ -296,11 +299,62 @@ describe('Actions: Auth', () => {
296299
expect(err).to.be.undefined
297300
})
298301
})
299-
it('dispatches for all other errors', () => {
300-
return confirmPasswordReset(dispatch, fakeFirebase, 'auth/user-not-found', 'error')
301-
.catch((err) => {
302-
expect(err.code).to.be.a.string
302+
describe('handles error code: ', () => {
303+
it('auth/expired-action-code', () => {
304+
return confirmPasswordReset(dispatch, fakeFirebase, 'auth/expired-action-code', 'error')
305+
.catch((err) => {
306+
expect(err.code).to.be.a.string
307+
})
308+
})
309+
it('auth/invalid-action-code', () => {
310+
return confirmPasswordReset(dispatch, fakeFirebase, 'auth/invalid-action-code', 'error')
311+
.catch((err) => {
312+
expect(err.code).to.be.a.string
313+
})
314+
})
315+
it('auth/user-disabled', () => {
316+
return confirmPasswordReset(dispatch, fakeFirebase, 'auth/user-disabled', 'error')
317+
.catch((err) => {
318+
expect(err.code).to.be.a.string
319+
})
320+
})
321+
it('auth/user-not-found', () => {
322+
return confirmPasswordReset(dispatch, fakeFirebase, 'auth/user-not-found', 'error')
323+
.catch((err) => {
324+
expect(err.code).to.be.a.string
325+
})
326+
})
327+
it('auth/weak-password', () => {
328+
return confirmPasswordReset(dispatch, fakeFirebase, 'auth/weak-password', 'error')
329+
.catch((err) => {
330+
console.log('error:', err)
331+
expect(err.code).to.be.a.string
332+
})
333+
})
334+
it('other', () => {
335+
return confirmPasswordReset(dispatch, fakeFirebase, 'asdfasdf', 'error')
336+
.catch((err) => {
337+
expect(err.code).to.be.a.string
338+
})
339+
})
340+
})
341+
342+
})
343+
344+
describe('verifyPasswordResetCode', () => {
345+
it('resolves for valid code', () => {
346+
return verifyPasswordResetCode(dispatch, fakeFirebase, 'test')
347+
.then((res) => {
348+
expect(res).to.equal('success')
303349
})
304350
})
351+
describe('handles error code: ', () => {
352+
it('other', () => {
353+
return verifyPasswordResetCode(dispatch, fakeFirebase, 'error')
354+
.catch((err) => {
355+
expect(err.code).to.be.a.string
356+
})
357+
})
358+
})
305359
})
306360
})

0 commit comments

Comments
 (0)