diff --git a/src/constructor.js b/src/constructor.js index 3b8f1ca..b99fb87 100644 --- a/src/constructor.js +++ b/src/constructor.js @@ -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' /** @@ -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) @@ -182,6 +183,8 @@ const EcomPassport = function ( this.popupLogin = (enableSkip, baseUri) => methodsMiddleware(popupLogin, [enableSkip, baseUri]) + this.sendEmailCode = email => methodsMiddleware(sendEmailCode, [email]) + loadStoredSession(ecomPassport) } diff --git a/src/methods/fetch-login.js b/src/methods/fetch-login.js index 2d8d1ce..225f458 100644 --- a/src/methods/fetch-login.js +++ b/src/methods/fetch-login.js @@ -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} * * @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)