react-native-zalo-kit
v6.0.0
Published
Zalo SDK (login and user profile) for React Native and Expo
Maintainers
Readme
Zalo Kit for React Native
Zalo Kit is a React Native wrapper around the official Zalo SDKs for Android and iOS, for apps that want "Log in with Zalo" and the user's basic profile.
Features
- Login through the Zalo app or the web, with automatic web fallback when the app is missing. Failures reject with an error code, so the promise never hangs.
- Access tokens are refreshed for you. Concurrent calls share one refresh, since Zalo refresh tokens are single-use.
- Tokens are encrypted with the Android Keystore and kept in the iOS Keychain. Sessions saved by 5.x are migrated.
getUserProfile()returns the user's ID, name and avatar.- An Expo config plugin sets up both platforms from one line in
app.json. - On Android there is nothing to add to
MainActivityorMainApplication, and the ProGuard rules are included.
Installation
npm install react-native-zalo-kit
# or
yarn add react-native-zalo-kit
# iOS (React Native CLI)
cd ios && pod installThen create a Zalo app to get your Zalo App ID.
Expo: add the config plugin, then run npx expo prebuild or build with EAS. Expo Go is not supported; use a development build.
{
"expo": {
"plugins": [["react-native-zalo-kit", { "appId": "<YOUR_ZALO_APP_ID>" }]]
}
}React Native CLI: follow the iOS and Android setup.
Quick start
import {
ErrorCodes,
getAccessToken,
getUserProfile,
login,
logout,
} from 'react-native-zalo-kit';
try {
await login(); // Zalo app if available, otherwise web login
} catch (e: any) {
if (e.code === ErrorCodes.ZALO_NOT_INSTALLED) {
// ...
}
}
const { id, name, picture } = await getUserProfile();
const { accessToken } = await getAccessToken(); // refreshed automatically
logout();Documentation
Everything else lives on the documentation site: https://maitrungduc1410.github.io/react-native-zalo-kit/
- Login and web fallback
- Tokens and sessions
- User profile
- Error handling
- Migrating from 5.x
- Troubleshooting and known Zalo-side issues
- API reference
A complete demo app is in example/.
Contributing
See CONTRIBUTING.md. The docs site source is in docs/; run yarn docs:dev to work on it. ARCHITECTURE.md explains how the library works inside.
License
MIT
If you like this project, encourage me by giving it a ⭐️. Happy hacking
