Hosted account#

The hosted account runs on the domain in the channel's My account link, for example https://account.shop.com. You set it up like the checkout's domain, with the domain for the hosted account.

There, a logged-in customer can:

  • view orders and reorder them;
  • view and download invoices;
  • follow shipments;
  • manage the profile, addresses and password;
  • manage organisations and the colleagues who share them;
  • request returns, when returns are turned on for the channel.

Link to the account from your storefront, for example to https://account.shop.com/account/orders. A customer who isn't logged in there is sent to its sign-in page.

·
Note:

The hosted checkout only offers logging in when the channel has a My account link.


Sharing the login#

The hosted checkout and account keep the user token in a cookie named af-sid. When your storefront stores the token from logInCustomer in that same cookie, the customer is logged in on the checkout and the account too, and the other way round.

AttributeValue
Nameaf-sid
ValueThe user token itself, as returned by logInCustomer, registerCustomer, verifyCustomer or logInAsOrganisation.
DomainYour shop's domain with a leading dot, for example .shop.com, so every subdomain can read it.
Path/
SecureYes
HttpOnlyNo: the hosted pages read it in the browser.
ExpiresOne day, or expires_at of the token.
const { token, expires_at } = data.logInCustomer;

document.cookie = [
  `af-sid=${token}`,
  'domain=.shop.com',
  'path=/',
  `expires=${new Date(expires_at).toUTCString()}`,
  'secure',
].join('; ');

This only works when the storefront, the checkout and the account are on the same domain, for example www.shop.com, checkout.shop.com and account.shop.com.

The hosted pages ignore and remove an af-sid that has expired. The checkout then asks the customer to log in again.

After logInAsOrganisation or logOutAsOrganisation, write the new token to af-sid as well.

Logging out#

There is no logout call: the user token stays valid until it expires. To log the customer out, delete af-sid on the same domain and path, and drop the token from your storefront.

document.cookie =
  'af-sid=; domain=.shop.com; path=/; expires=Thu, 01 Jan 1970 00:00:00 GMT; secure';

When the customer logs out in the hosted account, it deletes af-sid and shows its sign-in page; it doesn't send the customer back to the storefront. Read af-sid when a page of your storefront loads, so the storefront notices the logout too.

Query Runnerhttps://afosto.app/graphql

No query loaded

Click play on any code block in the docs to load a query here.