openbridge.customer.init()
Initializes the customer session by checking for a stored access token. If a valid token exists, fetches and returns the customer data. Call this on page load to restore logged-in state.
Returns
Promise<ShopifyCustomer | null> - Customer object if logged in, null otherwise.
Examples
Basic initialization
// On page load
const customer = await openbridge.customer.init()
if (customer) {
console.log(`Logged in as ${customer.email}`)
showAccountMenu()
} else {
showLoginForm()
}
Handling an expired session
.init() never throws — if the stored token is invalid or expired, the token is cleared and null is returned.
const customer = await openbridge.customer.init()
if (customer) {
updateUI(customer)
} else {
// No valid session — show the logged-out state
showLoginForm()
}
Combined with subscribe
// Set up subscription first
openbridge.customer.subscribe((customer) => {
updateNavbar(customer)
})
// Then initialize - will trigger subscriber with restored state
await openbridge.customer.init()
Always call .init() early in your page lifecycle. This restores the customer session and triggers any subscribers with the current state.