Skip to content

Commit

Permalink
feat(fetch-login): new optional emailCode param for login with emai…
Browse files Browse the repository at this point in the history
…l and verification code

ecomplus/passport#17
  • Loading branch information
leomp12 committed Sep 13, 2021
1 parent 9589c2f commit 6e0abb4
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
5 changes: 4 additions & 1 deletion src/constructor.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import checkVerification from './methods/check-verification'
import logout from './methods/logout'
import popupOauthLink from './methods/popup-oauth-link'
import popupLogin from './methods/popup-login'
import sendEmailCode from './methods/send-email-code'
import requestApi from './methods/request-api'

/**
Expand Down Expand Up @@ -166,7 +167,7 @@ const EcomPassport = function (

this.checkVerification = () => methodsMiddleware(checkVerification)

this.fetchLogin = (email, docNumber) => methodsMiddleware(fetchLogin, [email, docNumber])
this.fetchLogin = (email, docNumber, emailCode) => methodsMiddleware(fetchLogin, [email, docNumber, emailCode])

this.fetchOauthProfile = () => methodsMiddleware(fetchOauthProfile)

Expand All @@ -182,6 +183,8 @@ const EcomPassport = function (

this.popupLogin = (enableSkip, baseUri) => methodsMiddleware(popupLogin, [enableSkip, baseUri])

this.sendEmailCode = email => methodsMiddleware(sendEmailCode, [email])

loadStoredSession(ecomPassport)
}

Expand Down
13 changes: 11 additions & 2 deletions src/methods/fetch-login.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,31 @@ import { passport } from '@ecomplus/client'
*
* @param {string} email - Customer main email address
* @param {string} [docNumber] - Customer document number
* @param {string} [emailCode] - Email verification code
*
* @returns {Promise<session|error>}
*
* @example
// Account identification only
ecomPassport.fetchLogin('example@mail.com')
// Partial authorization with email + doc number
ecomPassport.fetchLogin('example@mail.com', '1234567890')
// Full authorization with verification code received by email
ecomPassport.fetchLogin('example@mail.com', null, 123456)
*/

export default ({ storeId, setSession }, emitter, [email, docNumber = null]) => passport({
export default ({ storeId, setSession }, emitter, [email, docNumber = null, emailCode = null]) => passport({
url: '/identify.json',
storeId,
method: 'POST',
data: {
email,
doc_number: docNumber
doc_number: docNumber,
email_code: emailCode
}
}).then(({ data }) => {
setSession(data)
Expand Down

0 comments on commit 6e0abb4

Please sign in to comment.