Skip to main content
The login service handles authentication for the customer portal — passwordless email codes, social providers (Google, Facebook), and the token lifecycle that follows. It writes tokens to local storage so subsequent requests stay authenticated.

Setup

The login service depends on three other dependencies passed at construction time:
  • adapter — connects to the auth backend (passwordless start/verify, social authenticate, refresh token).
  • router — a minimal router with push / replace so the service can redirect post-login.
  • shop{ domain, locale }; locale can be a Signal<string> so login adopts the current theme locale.

Shape

Example: passwordless start

Token management

getToken() returns the current access token, refreshing it transparently if it has expired (using the stored refresh token). Wire it into the fetch layer to ensure all API requests include a valid access token: