Skip to content

Customer portal

The site client’s portal signs the workspace’s contacts in on the site itself, as the customer portal does: a six-digit code emailed from the workspace’s sending address, then a session. With it, the site shows what the contact has with the business.

// In the site's Worker, from its own sign-in form.
const digize = createSiteClient({ request });
await digize.portal.requestCode(email, { turnstileToken });
const session = await digize.portal.signIn(email, code);
// Keep the token in an HttpOnly cookie, never where the page's scripts can read it.
const account = await digize.portal.account(session.token);
for (const invoice of account.invoices) {
// Each record links to the page that acts on it: pay, accept, reschedule, sign.
console.log(invoice.number, invoice.href);
}
await digize.portal.signOut(session.token);
Method Answers
requestCode(email, { turnstileToken }) { sent: true }, whether or not the address is a contact’s. Only a contact’s address gets a code, good for ten minutes and five tries.
signIn(email, code) token and expiresAt: the session lasts 30 days, until it’s signed out, or until the contact is deleted.
account(token) business (name, logo, accent, time zone, currency), welcome, profile, and the sections the portal shows: invoices, quotes, bookings, orders, documents and subscriptions, each record with an absolute link (href, and payUrl or returnsUrl on orders) to its page. A token that no longer works answers unauthorized.
signOut(token) { signedOut: true }; the session ends everywhere at once.

The portal must be open (Settings › Customer portal) and the workspace needs a sending domain for the codes, as on the portal’s own pages.