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
}| Field | Description |
|---|---|
token | JWT used on later requests |
merchant.sellerName | Store name |
merchant.billingMode | PREPAID or POSTPAID |
merchant.walletBalance | Balance in KWD |
merchant.scheduledDeliveryEnabled | Whether 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;
}
}