Behio Storefront SDK
Getting Started

Authentication

Customer registration, login, and token management

Register

const tokens = await client.auth.register({
  email: '[email protected]',
  password: 'securePassword123',
  firstName: 'Jan',
  lastName: 'Novak',
});
// tokens: { accessToken, refreshToken }
// Tokens are automatically stored in the client

Login

const tokens = await client.auth.login({
  email: '[email protected]',
  password: 'securePassword123',
});

Token Refresh

The SDK automatically refreshes expired tokens on 401 responses. You can also refresh manually:

const newTokens = await client.auth.refresh();

Logout

await client.auth.logout();
// Tokens cleared, refresh token invalidated server-side

Password Reset

// Request reset email
await client.auth.forgotPassword('[email protected]');

// Reset with token from email
await client.auth.resetPassword(token, 'newSecurePassword');

Events

Listen to auth lifecycle events:

client.on('auth:login', (data) => {
  console.log('Logged in:', data.email);
});

client.on('auth:logout', () => {
  // Redirect to login page
});

client.on('auth:token-refresh', () => {
  // Token refreshed silently
});

client.on('auth:token-refresh-failed', () => {
  // Refresh failed — user needs to re-login
});

Persisting Tokens

Store tokens in localStorage or cookies and restore on page load:

// Save after login
client.on('auth:login', () => {
  localStorage.setItem('tokens', JSON.stringify({
    accessToken: client.getAccessToken(),
    refreshToken: client.getRefreshToken(),
  }));
});

// Restore on init
const saved = localStorage.getItem('tokens');
if (saved) {
  client.setTokens(JSON.parse(saved));
}

On this page