Customers & custom fields
Shoppers create an account on your storefront with a password, Google, or a one-time email code. Each account has an email, an optional name, and any custom fields you define: extra data you keep on a customer, such as a birthday, a loyalty tier, newsletter topics, or internal notes.
Custom fields
A custom field is a typed value you define once for the whole store. NanoSite's model follows Shopify's customer metafields: a definition says what the field is and who may read or write it, and each customer stores a value under the field's key.
Create fields in the backoffice under Store → Customers → Custom fields, through the admin API, or by asking the AI builder ("collect the shopper's birthday at sign-up").
| Property | Description |
|---|---|
key |
Lowercase snake_case, starting with a letter (e.g. birthday). Unique per store; can't be changed later. |
name |
The label shown in the backoffice and in generated forms. |
description |
Optional help text. |
type |
The value type (see below). |
validations |
Optional value rules (see below). |
access |
Who can read and write the value (see below). |
Types
| Type | Value |
|---|---|
single_line_text |
String, up to 255 characters. |
multi_line_text |
String, up to 10,000 characters. |
number_integer |
Whole number. |
number_decimal |
Any finite number. |
boolean |
true / false. |
date |
YYYY-MM-DD. |
url |
An http(s) URL. |
email |
An email address. |
json |
Any JSON value, up to 16 KB. |
Validations
- Text:
min/maxlength,regex(the value must match), andchoices(the value must be one of the list; forms render a select). - Numbers:
min/maxvalue.
Changing a field's rules doesn't rewrite stored values; the new rules apply to the next write.
Access
Every field sets access separately for each audience:
| Audience | Levels | Meaning |
|---|---|---|
admin |
read_write · read |
You and your staff, in the backoffice and admin API. read shows the value but doesn't let staff change it (e.g. a consent answer only the shopper should set). |
storefront |
none |
Public, logged-out reads. Always none on customer fields: a customer record is never public. |
customerAccount |
none · read · read_write |
The logged-in shopper, on their own account. read shows it to them; read_write lets them set it at sign-up and from their profile. |
New fields default to merchant-only: { admin: "read_write", storefront: "none", customerAccount: "none" }.
Make a field shopper-editable only when it's the shopper's own information. Never base a discount or
permission on a value shoppers can write.
Stored values
Values live on the customer's metadata, keyed by the field's key:
{ "birthday": "1990-02-28", "tier": "gold", "notes": "Prefers phone contact" }
- Shoppers only ever see fields whose
customerAccountaccess isreadorread_write. - Updates merge: send only the keys you change.
nullremoves a value. - You (and the admin API) can also store keys that have no field definition. They stay merchant-only.
- Keys starting with
$are reserved for platform data and are read-only. For example, customers imported from Shopify or WooCommerce keep their source id, phone, tags and marketing consent under$import. - Deleting a field keeps its stored values; they become merchant-only.
On the storefront
import {
useListCustomerFields, useRegisterCustomer, useUpdateCurrentCustomer, useGetCurrentCustomer,
} from "@nanosite/ecommerce-sdk";
// The fields the shopper can see: [{ key, name, description, type, validations, writable }]
const fields = useListCustomerFields();
// Sign-up: set any writable fields.
useRegisterCustomer().mutate({
data: { email, password, name, metadata: { birthday: "1990-02-28" } },
});
// Profile page: current values are on the customer from `/me`.
const me = useGetCurrentCustomer(); // me.data.data.metadata.birthday
useUpdateCurrentCustomer().mutate({
data: { name, metadata: { birthday: "1990-03-01", newsletter_topic: null } },
});
Build the sign-up and profile forms from useListCustomerFields(), rendering an input only for
writable fields. A write to a field the shopper can't edit, or a value that breaks the field's
rules, returns 400 with the reason.
In the admin API
| Endpoint | Hook | Purpose |
|---|---|---|
GET /admin/custom-fields?ownerType=customer |
useListCustomFieldDefinitions |
List field definitions. |
POST /admin/custom-fields |
useCreateCustomFieldDefinition |
Define a field. |
PATCH /admin/custom-fields/:id |
useUpdateCustomFieldDefinition |
Change name, type, rules or access (not the key). |
DELETE /admin/custom-fields/:id |
useDeleteCustomFieldDefinition |
Remove a definition (values are kept). |
GET /admin/customers, GET /admin/customers/:id |
useListAdminCustomers, useGetAdminCustomer |
Customers with all their stored values. |
PATCH /admin/customers/:id |
useUpdateAdminCustomer |
Update a customer's name and values (merge; null clears). |
POST /admin/custom-fields
{
"ownerType": "customer",
"key": "tier",
"name": "Loyalty tier",
"type": "single_line_text",
"validations": { "choices": ["bronze", "silver", "gold"] },
"access": { "admin": "read_write", "storefront": "none", "customerAccount": "read" }
}
Limits
- Up to 50 custom fields per store for customers.
- Up to 64 KB of stored values per customer.