Handle customer authentication with E-Com Plus Passport
The @ecomplus/passport-client
package can be used to handle login and persist/manipulate customer account data trough E-Com Plus Passport and Store APIs.
It's available for both Node.js and browser environments.
import ecomPassport from '@ecomplus/passport-client'
ecomPassport.fetchLogin(localStorage.getItem('email'), localStorage.getItem('doc_number'))
ecomPassport.on('logout', () => {
console.log('User logged OUT')
})
ecomPassport.on('login', () => {
console.log('User logged IN', ecomPassport.getCustomer())
ecomPassport.fetchOrdersList()
.then(orders => {
console.log('Listing customer orders', orders)
})
})
It may require and doesn't include core-js
(optional) and @ecomplus/utils
(peer dependency).
npm i --save core-js @ecomplus/utils @ecomplus/passport-client
npm i --save @ecomplus/utils @ecomplus/passport-client
<script src="https://cdn.jsdelivr.net/npm/@ecomplus/passport-client/dist/ecom-passport.var.min.js"></script>
When importing from CDN, EventEmitter3
, ecomUtils
and ecomClient
libraries must be included separately and available on window scope.