shoppy.customer.login(email, password)
Authenticates a customer using their email and password. On success, stores the access token and returns the customer data.
Parameters
| Param | Type | Required | Description |
|---|
email | string | Yes | Customer’s email address |
password | string | Yes | Customer’s password |
Returns
Promise<ShopifyCustomer> - The authenticated customer object.
Throws
Error - If credentials are invalid or login fails.
Examples
Basic login
try {
const customer = await shoppy.customer.login(
'[email protected]',
'password123'
)
console.log(`Welcome, ${customer.firstName}!`)
redirectToDashboard()
} catch (error) {
showError(error.message) // "Unidentified customer"
}
document.querySelector('#login-form').addEventListener('submit', async (e) => {
e.preventDefault()
const email = document.querySelector('#email').value
const password = document.querySelector('#password').value
try {
await shoppy.customer.login(email, password)
window.location.href = '/account'
} catch (error) {
document.querySelector('#error').textContent = error.message
}
})
Check if already logged in
if (shoppy.customer.isLoggedIn()) {
// Already authenticated
redirectToAccount()
} else {
// Show login form
showLoginForm()
}
Never store passwords. The SDK only sends credentials to Shopify’s secure API and stores only the resulting access token.