JWT authentication for the React Native app.

flasho.auth

flasho.auth

Use JWT login in the React Native app. Use an API key only on a server. See Setup.

login()

import { FlashoApiError } from 'flasho-merchant-sdk';
import { flasho } from './flasho';
 
export async function login(email: string, password: string) {
  const result = await flasho.auth.login({ email, password });
  // result.token is stored on the client automatically
  return result.merchant; // sellerName, billingMode, walletBalance
}
FieldDescription
tokenJWT used on later requests
merchant.sellerNameStore name
merchant.billingModePREPAID or POSTPAID
merchant.walletBalanceBalance in KWD
merchant.scheduledDeliveryEnabledWhether scheduled delivery is on

⚠️ Token expiry

When a call throws FlashoApiError with isUnauthorized, the JWT has expired. Call login() again and retry.

import { FlashoApiError } from 'flasho-merchant-sdk';
 
async function book(request: CreateDeliveryRequest, email: string, password: string) {
  try {
    return await flasho.deliveries.create(request);
  } catch (err) {
    if (err instanceof FlashoApiError && err.isUnauthorized) {
      await flasho.auth.login({ email, password });
      return await flasho.deliveries.create(request);
    }
    throw err;
  }
}