Customer accounts
Sign-in, registration, and framework-generated account routes.
Last updated:
Accounts are optional for browsing and guest checkout. Sign-in, profiles,
addresses, and orders are handled by the framework with Better Auth: you do not
need AuthProvider or lib/auth* files.
Do not create pages/api/auth.$.ts or pages/api/$.ts; those routes are
reserved (/api/auth/* and /api/*).
1. Session
import { useAuth } from "@ecomiq/storefront";
export function SessionButton({
email,
password,
}: {
email: string;
password: string;
}) {
const { session, isPending, signIn, signOut } = useAuth();
if (isPending) return <span>Loading…</span>;
if (!session?.user) {
return (
<button onClick={() => void signIn({ email, password })}>Sign in</button>
);
}
return <button onClick={() => void signOut()}>Sign out</button>;
}2. Registration
registerCustomer requires the proxy client:
import { createStorefrontProxyApi, registerCustomer } from "@ecomiq/storefront";
await registerCustomer(createStorefrontProxyApi(), {
email: "andrea@example.com",
password: "a-secure-password",
firstName: "Andrea",
lastName: "Ramos",
countryIsoCode: "US",
phone: "+1 555 0100",
});After registration, call signIn to create the session.
Account routes
The framework generates and protects:
/api/*— same-origin API proxy./api/auth/*— Better Auth./account/— profile./account/addresses— addresses./account/ordersand/account/orders/:orderId— orders./account/devices— informational screen; the devices endpoint does not exist yet.
/login and /register are not generated. You must create them under pages/.
The getCustomerMe, patchCustomer, getCustomerAddresses,
createCustomerAddress, updateCustomerAddress, deleteCustomerAddress,
getCustomerOrders, and getCustomerOrder helpers receive an Api first:
import { createStorefrontProxyApi, getCustomerMe } from "@ecomiq/storefront";
const customer = await getCustomerMe(createStorefrontProxyApi());Server variables
| Variable | Use |
|---|---|
BETTER_AUTH_SECRET | Session secret; configure it as a production secret. |
STOREFRONT_API_URL | API used for sign-in; defaults to https://storefront.ecomiq.pe. |
BETTER_AUTH_TRUSTED_HOSTS | Comma-separated allowed hosts; normally optional. |
Sign-in API
api.baseUrl in ecomiq.config.js configures serverApi, but Better Auth
sign-in uses STOREFRONT_API_URL. When targeting another environment, point
both values to the same API.