Skip to main content
The AuthenticationService (accessed via client.authentication) creates shopper accounts and issues their sessions. It handles sign-up with email confirmation, sign-in by password or emailed code, password recovery, session refresh and sign-out. Every customer-scoped operation across the SDK, on client.customers, client.cartWishlist, client.giftCards and client.messaging among others, takes the session’s access_token as the xAuthToken header. The access_token is the store’s sign-in token: it is issued by the store and environment of the API key that created the session, and no other store accepts it.
Already using your own auth provider? If your storefront authenticates through Auth0, Clerk, Cognito, Firebase, NextAuth, SSO, or any other external identity system, you don’t need this service. Use CustomersService to provision Galactic Core customer records directly from your backend. See Customers and Auth for the decision matrix.
Every method on this service is called with a secret key (tybrite_sk_*) from your server; a publishable key answers 403. getCurrentUser is the exception and accepts either key.

The Customer Session Lifecycle

A session is the object { access_token, refresh_token, expires_in, expires_at, token_type }, and token_type is always shopper.
A customer-scoped call whose xAuthToken is expired, revoked, issued by another store or environment, or malformed answers 401 invalid_token. The storefront refreshes the session once and treats the shopper as signed out if the refresh also fails.
On a marketplace key, the session belongs to the marketplace, and customer in the responses below is null because a marketplace shopper has an account without a per-store customer record. A marketplace adds purchases made as a guest with an email address to the account only when user.email_verified is true, which is the case once the address has been confirmed.

The customer in sign-in responses

Sign-in responses (verifyRegistration, login, verifyOtp, resetPassword, claimAccountFromOrder) and getCurrentUser return the shopper’s customer record in a short form: identity, phone (an empty string when none was given), the tier the merchant assigned (new customers start at bronze), and purchase totals, with total_purchases in the store’s currency as a decimal major-unit amount. The full record, with address, status, consent and custom fields, comes from the customer methods.

Sign-up

register

Start a customer account. register does not return a session: every call answers 202 Accepted with the same body, whether the address is new or already has an account, and sends one email.
  • A new address receives a confirmation code and, when redirect_to is allowed, a confirmation link.
  • An address that already has an account receives a notice that an account exists, with directions to sign in or reset the password.
The account and the first session are created by verifyRegistration. Until the address is confirmed no account exists, so the response reveals nothing about which addresses have one. password is optional. An account created without one signs in by emailed code (sendMagicLink, then verifyOtp) and can set a password later with changePassword. When a password is sent, verifyRegistration must carry the same password. The password and profile of the most recent call for an address are the ones that apply. A repeat call within 60 seconds sends no second email: the code already sent confirms with the newest call’s password. When no unexpired code is waiting and the address is still being slowed, the call answers 429 rate_limited with Retry-After. redirect_to is the storefront page that receives the shopper from the email. The email appends ?link_token=<token> to it, and the page passes that token to verifyRegistration. It must be on one of the store’s allowed storefront origins, which the merchant sets in the dashboard; otherwise it is ignored and the email carries the code only. The email must be a real, deliverable address. Disposable and placeholder domains (example.com, test.com, known throwaway-mail providers, and similar) are rejected with 400 invalid_email. A password must be 8 to 72 characters long, counted as characters, and must not appear on the list of commonly used passwords, which is compared without regard to case. A password that breaks the rule is refused with 400 weak_password; details.rule identifies the rule.
The password rule is evaluated before the email is looked up, so the refusal is identical whether or not the email already has an account. The other 400 codes are invalid_request for a missing email or a field of the wrong type and invalid_email for a malformed, disposable or placeholder address. Pass marketing_consent: true when the sign-up form includes a marketing opt-in box and the customer checked it. It defaults to false: a customer is never subscribed to marketing without affirmative consent. The customer can change this later via updateCustomer.
Response (202)

verifyRegistration

Confirm the address and create the account. Send the six-digit code from the email with the email that registered, or send the link_token from the email’s link on its own. Returns 201 Created with the shopper, the customer record and the first session. A code is valid for 15 minutes and is accepted 5 times. A link_token is single-use and shares its code’s expiry and attempts. A registration that carried a password is confirmed only with that same password alongside the code or link; a missing or different password answers 400 invalid_code with details.reason wrong, counts as one of the code’s attempts, and leaves the code usable. Omit password when the registration carried none. When the address already had an account the code is consumed and the call answers 400 invalid_code, the same as a wrong code. A refused call carries the reason in details.reason:
Response (201)
Response (400)
Response shape:

resendRegistration

Send a new confirmation code and link to an address that registered and has not yet confirmed. The earlier code stops working. The call answers 202 Accepted with the same body as register for every address, and sends one email: a fresh confirmation for a pending registration, or the notice that an account exists when the address already has one. At most one email per address is sent every 60 seconds and five an hour. A call past that is answered 202 and sends nothing.
Response (202)

Sign-in

login

Authenticate an existing customer with email and password. Returns 200 OK. Every refusal that depends on the account answers 401 invalid_credentials with the same body: an address with no account, a wrong password, an account that has not been confirmed, a disabled account, and an account that has no password. 401 password_reset_required is returned only after the correct password, for an account that must set a new one through forgotPassword and resetPassword. Repeated wrong passwords lock an account for a short period, during which every call for it answers 429 rate_limited with Retry-After.
Response (200)
Response (401)

Send a one-time sign-in code, and a link carrying it, to an address that has an account. Any account can sign in this way, with or without a password. The code is six digits and is valid for 15 minutes. The call answers 202 Accepted with the same body for every address; an address without an account receives no email, and no account is created. Sign-in by code is on for every store unless the merchant switches it off. store.auth.passwordless in the store information (client.system.getStoreInfo) reports the setting, and while it is false this method and verifyOtp answer 403 passwordless_disabled. redirect_to is the storefront page that receives the shopper from the email, which appends ?link_token=<token> to it. It must be on one of the store’s allowed storefront origins; otherwise it is ignored and the email carries the code only. At most one email per address is sent every 60 seconds and five an hour. A call past that is answered 202 and sends nothing.
Response (202)

verifyOtp

Complete sign-in with the code from the sign-in email, or with the link_token its link carries. Returns 200 OK with the same shape as login: message, user, customer and session. A code is valid for 15 minutes, is accepted 5 times and works once. A wrong, expired, used or unknown code answers 400 invalid_code with no reason, and an address without an account answers the same way. This method never creates an account.
Response (200)

Password Management

forgotPassword

Send a password reset code, and a link carrying it, to an address that has an account. The call answers 202 Accepted with the same body for every address; an address without an account receives no email. The shopper completes the reset with resetPassword. The code is six digits and is valid for 15 minutes. redirect_to is the storefront page that receives the shopper from the email, which appends ?link_token=<token> to it. It must be on one of the store’s allowed storefront origins; otherwise it is ignored and the email carries the code only.
Response (202)

resetPassword

Set a new password with the code from the reset email, or with the link_token its link carries. Every earlier session of the account ends, the account is sent a notice that its password changed, and the response is a new session with the same shape as login. A reset also clears a password_reset_required state. A wrong, expired or used code answers 400 invalid_code with no reason. The new password follows the password rule that applies to register; a password that breaks it is refused with 400 weak_password.
Response (200)

changePassword

Change the password of the signed-in shopper, or set one for an account that has none. Every other session of the account ends, the account is sent a notice that its password changed, and the response carries a new session for the caller. Returns 200 OK. current_password is required when the account has a password (user.has_password is true) and is checked first. A wrong one answers 401 invalid_credentials and counts toward the account’s lock. An account created for sign-in by emailed code has no password, so it omits current_password. The new password follows the password rule that applies to register.
xAuthToken is mandatory and must be the customer’s own sign-in token (the access_token from a session). Server keys cannot stand in: this method changes the customer’s login credentials and requires per-customer authorization.
Response (200)

Session Utilities

refreshToken

Exchange a refresh token for a new session. Returns 200 OK. The refresh token works once: the response carries a replacement, and the earlier token stops working the moment the new one is issued. Store the new access_token and refresh_token on every refresh. A refresh that cannot be honoured answers 401 invalid_refresh_token: the token has expired, its session ended through logout or a password change, it belongs to another store or environment, or it was presented a second time. Presenting a used token again ends its whole session. Two refreshes with the same token at once therefore leave one of them refused, so a storefront serialises refreshes per session. On invalid_refresh_token the shopper is signed out.
Response (200)
Schedule the refresh shortly before expires_at, or refresh once when a customer-scoped call answers 401 invalid_token. Refreshing ahead of expiry avoids cart and wishlist write failures during checkout.

logout

End a session. Send the refresh_token of the session: the whole session is revoked, so no refresh token issued since the sign-in works again. The call answers 204 No Content for every request, including a refresh token that is unknown or already ended, so a storefront can call it whenever a shopper leaves. An access token already issued stays valid until its expires_at, at most 15 minutes.

getCurrentUser

Return the signed-in shopper and their customer record, read from the sign-in token. Also routed as GET /v1/auth/me. Returns 200 OK with { user, customer }. customer is null on a marketplace key.
xAuthToken is mandatory and must be the customer’s own sign-in token. A token that is expired, revoked, issued by another store or environment, or malformed answers 401 invalid_token.
Response (200)
getCurrentUser returns just enough to identify the customer. For the complete profile, including addresses, store metrics, purchase history and status, call CustomersService.getCustomer; the same xAuthToken works there. Profile edits live on CustomersService via updateCustomer.

Claiming an account from a guest order

A guest who checks out without an account can set a password on the order confirmation page and keep the order. A secret-key createOrder call for a guest returns a one-time claim_token on the order; the storefront’s server passes it to claimAccountFromOrder together with the password the shopper chose. The token is a credential and is shown once.

claimAccountFromOrder

Create an account from a guest order. Turn a guest order into an account. The guest sets a password on the order confirmation page and receives a signed-in session for a new account that owns that order and saves its shipping address. The credential is the claim_token returned once by POST /v1/orders when the order was created. The account is bound to the order’s email address; no other address can be claimed. A token works once and expires (7 days by default; the store can change this or turn the feature off). The token proves possession of the order confirmation, not of the mailbox, so the account starts with email_verified: false. It becomes verified when the shopper signs in with an emailed code or resets their password; at that moment every session issued before is revoked and, unless the password was just replaced, a new password is required at the next password sign-in. Refusals. A token that is wrong, spent, expired, for another store or environment, or for an unknown order answers 404 not_found, identically. Once the token is valid: 409 account_exists when the address already has an account at this store (nothing is linked; the shopper signs in), and 409 claim_unavailable when the address already has other orders with this store (the shopper registers with an emailed code, which proves the mailbox and brings the orders together). A weak password is 400 weak_password, checked first, as on registration. Only the order for this token is claimed. Other guest orders for the same address are not linked. Secret key required. This endpoint requires a secret key (tybrite_sk_*), called from the storefront’s server. Publishable keys answer 403 forbidden. Attempt limits: 10 attempts per order per hour and 600 per store per hour; past either, the call answers 429 rate_limited with a Retry-After header. After 10 wrong tokens an order’s token is locked.
Response
POST /v1/auth/claim-account

Full Lifecycle Example

This walks the customer from sign-up, through a cart mutation and checkout, to logout, showing where xAuthToken flows.

Response Codes

Attempt limits

Attempts are limited by where they come from. Every attempt counts, successful or not, and an address with no account is treated identically, so a 429 says nothing about whether an account exists. A refused call returns 429 rate_limited with a Retry-After header giving the seconds to wait. With a secret key (a storefront’s server, whose address is not the shopper’s), each method is limited per store and email address. Past the threshold the account is not refused; it is slowed to one attempt per interval, and Retry-After gives the seconds until the next one is accepted. With a publishable key (a browser), attempts are limited per calling address: 20 per address and email, and 60 per address across all emails, in 15 minutes. Across every store and address, a higher per-email threshold slows an attack spread over many sources: Session calls are limited per token: refreshToken and logout 20 per refresh token and changePassword 5 per sign-in token in 15 minutes, getCurrentUser 120 per sign-in token per minute.
Token Lifetime: Access tokens are valid for 15 minutes. A storefront calls refreshToken before expires_at, or once on 401 invalid_token, and stores the replacement pair each time.