Authentication & Setup
1. Setup and Configure Axios
The package requires Axios to manage API calls. Install Axios ("axios": "^1.7.4"
) and configure it:
const api = axios.create(
Object.assign({}, axiosConfig, {
headers: {
get: {
"Accept-Language": "EN", // Set locale
},
},
})
);
api.interceptors.request.use((config) => {
config.headers["xb-tenant"] = ""; // TENANT is required
config.headers.Authorization = `Bearer ${sessionToken}`;
return config;
});
Note: Axios is not bundled to reduce package size.
Example API Call
import { getUserByHandle, PublicProfile } from "@xborglabs/ui-shared";
const publicProfile: PublicProfile = await getUserByHandle({
api,
userHandle: "easteregg",
communityId: "abcdef",
});
Important: Only imports from
@xborglabs/ui-shared
are SSR-compatible.
2. Configure TanStack Query Provider
To use abstracted hooks, link your API configuration with the apiContext
:
const apiContext = ApiBase.getInstance();
apiContext.setApi(api);
Create a query client following the TanStack Query documentation.
Last updated