expo-cafebazaar-auth
v1.0.1
Published
Cafe Bazaar In-App Login for Expo (Android). Sign in with Bazaar account in your Expo/React Native app.
Maintainers
Readme
expo-cafebazaar-auth
Expo native module for Cafe Bazaar In-App Login on Android only. Use Bazaar (Cafe Bazaar) account sign-in in your Expo / React Native app.
Requirements
- Platform: Android only. This package does not include iOS native code.
- Build: A development build is required. The module does not work in Expo Go (the native module will be
null). - Prebuild: You must run
npx expo prebuild(at least once) so the config plugin can copy the vendor and wire the Android project.
Installation
npx expo install expo-cafebazaar-auth
# or
npm install expo-cafebazaar-auth
yarn add expo-cafebazaar-auth
pnpm add expo-cafebazaar-authSetup
1. Add the config plugin
In app.json (or app.config.js), add "expo-cafebazaar-auth" to expo.plugins:
{
"expo": {
"plugins": ["expo-cafebazaar-auth"]
}
}2. Run prebuild and build
The plugin runs at prebuild time. It:
- Copies the bundled CafeBazaarAuth vendor (core + auth) from the package into your project at
.expo/cafebazaar-auth/CafeBazaarAuth. - Registers the
:coreand:authprojects inandroid/settings.gradleso the native module can depend on them. - Applies Gradle patches (SDK versions, etc.) so the vendor builds correctly.
Run prebuild, then build and run on Android:
npx expo prebuild --platform android
npx expo run:androidYou can use npx expo run:android without a separate prebuild if your project is already configured; the plugin runs when the native project is generated or updated.
When the module is unavailable
The package uses requireOptionalNativeModule, so the default export may be null when:
- The app is running in Expo Go (no custom native code).
- The native module is not linked (e.g. missing plugin or prebuild).
On iOS, the package does not ship native code; the module is Android-only. In a multi-platform app, always guard usage:
- Check
Platform.OS === 'android'before calling Bazaar APIs. - Check that the default export is not null before calling any method (e.g.
CafeBazaarAuth?.isBazaarInstalled()or anif (CafeBazaarAuth) { ... }block).
For multi-platform apps, a small wrapper service (e.g. services/bazaarAuth.ts) that checks platform and null and exposes a single API is recommended, so the rest of the app works on iOS and in Expo Go without the native module.
API
Import the default export and use the methods below. Guard with null checks as needed.
| Method | Returns | Description |
| ------------------------------- | ---------------------------------------- | --------------------------------------------------------------------------- |
| isBazaarInstalled() | boolean | Whether the Bazaar app is installed on the device. |
| isNeededToUpdateBazaar() | boolean | Whether the Bazaar app needs to be updated for login. |
| signInAsync() | Promise<{ accountId: string } \| null> | Start sign-in flow; resolves with account or null (e.g. user cancelled). |
| signOutAsync() | Promise<void> | Sign out. |
| getLastSignedInAccountAsync() | Promise<{ accountId: string } \| null> | Get the last signed-in account without starting a new flow. |
| showInstallBazaar() | void | Open system UI to install Bazaar. |
| showUpdateBazaar() | void | Open system UI to update Bazaar. |
Typical sign-in flow
- If the module is null or not on Android, do not show Bazaar login (or show a message that it is Android-only).
- If
!isBazaarInstalled()→ callshowInstallBazaar(). - Else if
isNeededToUpdateBazaar()→ callshowUpdateBazaar(). - Else → call
signInAsync()and handle the returned account ornull.
Example
import { Platform } from "react-native";
import CafeBazaarAuth from "expo-cafebazaar-auth";
if (Platform.OS !== "android" || !CafeBazaarAuth) {
// Bazaar not available (iOS or Expo Go)
return;
}
if (!CafeBazaarAuth.isBazaarInstalled()) {
CafeBazaarAuth.showInstallBazaar();
} else if (CafeBazaarAuth.isNeededToUpdateBazaar()) {
CafeBazaarAuth.showUpdateBazaar();
} else {
const account = await CafeBazaarAuth.signInAsync();
if (account) console.log("accountId", account.accountId);
}TypeScript
Types are exported from the package:
import CafeBazaarAuth, { type BazaarAccount } from "expo-cafebazaar-auth";BazaarAccount has an accountId: string field.
Troubleshooting
Build error: project could not find :core or :auth
The Android project expects the CafeBazaarAuth :core and :auth subprojects, but they are not at the path Gradle is using.
Ensure
expo-cafebazaar-authis inexpo.pluginsinapp.json.Run
npx expo prebuild --platform androidso the plugin runs and populates.expo/cafebazaar-auth/CafeBazaarAuth.In
android/settings.gradle, the CafeBazaarAuth block should look like this (paths relative to theandroidfolder):// CafeBazaarAuth (expo-cafebazaar-auth) include ':core' project(':core').projectDir = new File(settingsDir, '../.expo/cafebazaar-auth/CafeBazaarAuth/core') include ':auth' project(':auth').projectDir = new File(settingsDir, '../.expo/cafebazaar-auth/CafeBazaarAuth/auth')If you see
../vendor/CafeBazaarAuthor another path, replace it with../.expo/cafebazaar-auth/CafeBazaarAuthas above and run prebuild again.
Build error: Unresolved reference for ir.cafebazaar (or similar)
The vendor was not copied or linked. Run npx expo prebuild so the plugin copies the bundled CafeBazaarAuth source and wires it. Ensure .expo/cafebazaar-auth/CafeBazaarAuth exists after prebuild.
References
| Resource | URL | | ----------------------------- | ------------------------------------------------------------------- | | Cafe Bazaar In-App Login docs | https://developers.cafebazaar.ir/fa/guidelines/feature/bazaar-login/in-app | | CafeBazaarAuth SDK (official) | https://github.com/cafebazaar/CafeBazaarAuth | | expo-cafebazaar-auth (npm) | https://www.npmjs.com/package/expo-cafebazaar-auth | | expo-cafebazaar-auth (GitHub) | https://github.com/ssshojaei/expo-cafebazaar-auth |
License
MIT. The bundled CafeBazaarAuth code (under vendor/CafeBazaarAuth) is from Cafe Bazaar’s CafeBazaarAuth repository; see that repo for its license and attribution.
