Skip to content
Merged

v3.11.0 #1149

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
feat(auth): support passwordless sign-in (#857) (#1064) - @komachi
  • Loading branch information
komachi authored Nov 23, 2021
commit 1be2b9fad74ddd7ec3e182c49e278c7ffb4284ca
3 changes: 2 additions & 1 deletion src/actions/auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -545,7 +545,8 @@ export const login = (dispatch, firebase, credentials) => {
if (
[
'signInWithEmailAndPassword',
'signInAndRetrieveDataWithEmailAndPassword'
'signInAndRetrieveDataWithEmailAndPassword',
'signInWithEmailLink'
].includes(method)
) {
return { user: userData }
Expand Down
1 change: 1 addition & 0 deletions src/createFirebaseInstance.js
Original file line number Diff line number Diff line change
Expand Up @@ -380,6 +380,7 @@ export default function createFirebaseInstance(firebase, configs, dispatch) {
* (popup | redirect) (only used with provider)
* @param {string} credentials.email - Credentials for authenticating
* @param {string} credentials.password - Credentials for authenticating (only used with email)
* @param {string} credentials.emailLink - emailLink for authenticating (only used with passwordless sign-in)
* @returns {Promise} Containing user's auth data
* @see https://react-redux-firebase.com/docs/auth.html#logincredentials
* @see https://react-redux-firebase.com/docs/api/firebaseInstance.html#login
Expand Down
8 changes: 7 additions & 1 deletion src/utils/auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,8 @@ export function getLoginMethodAndParams(firebase, credentials) {
scopes,
phoneNumber,
applicationVerifier,
credential
credential,
emailLink
} = credentials
// Credential Auth
if (credential) {
Expand Down Expand Up @@ -158,6 +159,11 @@ export function getLoginMethodAndParams(firebase, credentials) {
}
}

// Passwordless sign-in
if (emailLink && email) {
return { method: 'signInWithEmailLink', params: [email, emailLink] }
}

// Check for new sign in method (see #484 for more info)
// Note: usage of signInAndRetrieveDataWithEmailAndPassword is now a fallback since it is deprecated (see #484 for more info)
if (!firebase.auth().signInWithEmailAndPassword) {
Expand Down
24 changes: 24 additions & 0 deletions test/unit/createFirebaseInstance.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -456,6 +456,30 @@ describe('createFirebaseInstance', () => {
// signInWithEmailAndPassword is called on login with email
expect(loginSpy).to.have.been.calledOnce
})

it('calls firebase auth signInWithEmailLink', async () => {
const dispatchSpy = sinon.spy(() => {})
const loginSpy = sinon.spy(() => Promise.resolve({}))
const firebaseStub = {
auth: () => ({ signInWithEmailLink: loginSpy }),
_: firebase._
}
const firebaseInstance = createFirebaseInstance(
firebaseStub,
{},
dispatchSpy
)

expect(firebaseInstance.login).to.be.a.function
const email = '[email protected]'
const emailLink = 'https://example.com'
await firebaseInstance.login({
email,
emailLink
})
// signInWithEmailLink is called on passwordless sign-in
expect(loginSpy).to.have.been.calledOnce
})
})

describe('handleRedirectResult method', () => {
Expand Down