Skip to content

Commit

Permalink
Merge pull request #109 from elco45/master
Browse files Browse the repository at this point in the history
ADD updateEmail
  • Loading branch information
n6g7 authored Jun 3, 2018
2 parents 42a2370 + 9503b9a commit 9629323
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 2 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ Make sure your client provides a implementation of [`fetch`](https://developer.m
- [`*auth.signInWithRedirect(authProvider)`](https://n6g7.github.io/redux-saga-firebase/reference/auth#signInWithRedirect)
- [`*auth.signOut()`](https://n6g7.github.io/redux-saga-firebase/reference/auth#signOut)
- [`*auth.unlink(authProvider)`](https://n6g7.github.io/redux-saga-firebase/reference/auth#unlink)
- [`*auth.updateEmail(email)`](https://n6g7.github.io/redux-saga-firebase/reference/auth#updateEmail)
- [`*auth.updatePassword(password)`](https://n6g7.github.io/redux-saga-firebase/reference/auth#updatePassword)

**Database**
Expand Down
22 changes: 21 additions & 1 deletion docs/_reference/auth.md
Original file line number Diff line number Diff line change
Expand Up @@ -436,7 +436,27 @@ methods:
}
}
```
- signature: auth.updateEmail(email)
id: updateEmail
generator: true
description: Updates the user's email.
arguments:
- name: email
required: true
type: String
description: The user's email.
example: |
```javascript
function* updateEmailSaga(email) {
try {
yield call(rsf.auth.updateEmail, email);
yield put(updateEmail());
}
catch(error) {
yield put(updateEmailFailure(error));
}
}
```
- signature: auth.updatePassword(password)
id: updatePassword
generator: true
Expand Down
6 changes: 6 additions & 0 deletions src/auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,11 @@ function * unlink (provider) {
return yield call([auth.currentUser, auth.currentUser.unlink], provider)
}

function * updateEmail (email) {
const auth = this.app.auth()
return yield call([auth.currentUser, auth.currentUser.updateEmail], email)
}

function * updatePassword (password) {
const auth = this.app.auth()
return yield call([auth.currentUser, auth.currentUser.updatePassword], password)
Expand All @@ -133,5 +138,6 @@ export default {
signInWithRedirect,
signOut,
unlink,
updateEmail,
updatePassword
}
22 changes: 21 additions & 1 deletion src/auth.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ describe('auth', () => {
linkWithRedirect: jest.fn(),
sendEmailVerification: jest.fn(),
unlink: jest.fn(),
updatePassword: jest.fn()
updatePassword: jest.fn(),
updateEmail: jest.fn()
},
confirmPasswordReset: jest.fn(),
signOut: jest.fn()
Expand Down Expand Up @@ -248,6 +249,25 @@ describe('auth', () => {
})
})

describe('updateEmail(email)', () => {
it('works', () => {
const email = 'skqdk'
const iterator = authModule.updateEmail.call(
context,
email
)

expect(iterator.next().value).toEqual(
call([auth.currentUser, auth.currentUser.updateEmail], email)
)

expect(iterator.next()).toEqual({
done: true,
value: undefined
})
})
})

describe('updatePassword(password)', () => {
it('works', () => {
const password = 'skqdk'
Expand Down
1 change: 1 addition & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ class ReduxSagaFirebase {
signInWithRedirect: auth.signInWithRedirect.bind(this),
signOut: auth.signOut.bind(this),
unlink: auth.unlink.bind(this),
updateEmail: auth.updateEmail.bind(this),
updatePassword: auth.updatePassword.bind(this)
}

Expand Down
1 change: 1 addition & 0 deletions src/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ describe('ReduxSagaFirebase', () => {
expect(rsf.auth.signInWithPopup).toBeInstanceOf(Function)
expect(rsf.auth.signInWithRedirect).toBeInstanceOf(Function)
expect(rsf.auth.signOut).toBeInstanceOf(Function)
expect(rsf.auth.updateEmail).toBeInstanceOf(Function)
expect(rsf.auth.updatePassword).toBeInstanceOf(Function)
})

Expand Down

0 comments on commit 9629323

Please sign in to comment.