rembase-react-native
v1.0.0-beta.1
Published
Official React Native SDK for Rembase - a cross platform backend creation tool.
Maintainers
Readme
Rembase React Native SDK
Official React Native SDK for Rembase - a cross-platform backend creation tool. This SDK provides authentication, cloud functions, and other backend services for React Native and Expo applications.
Installation
npm install rembase-react-nativePeer Dependencies
Make sure you have the following peer dependencies installed:
npm install react react-native @react-native-async-storage/async-storageFor Expo projects, you can install the async storage package:
npx expo install @react-native-async-storage/async-storageQuick Start
1. Initialize Rembase
import { rembaseInitSync, CredentialTypes } from 'rembase-react-native';
// Initialize with your app credentials
const rembase = rembaseInitSync('your-app-id', 'your-project-id', 'your-region-code');2. Authentication
Email/Password Authentication
// Register a new user
await rembase.registerUser('[email protected]', 'password123');
// Login with email/password
const user = await rembase.login(CredentialTypes.email_password('[email protected]', 'password123'));
console.log('Logged in user:', user);Email OTP Authentication
// Send OTP to email
await rembase.send_email_otp('[email protected]');
// Login with OTP
const user = await rembase.login(CredentialTypes.email_otp('[email protected]', '123456'));WhatsApp OTP Authentication
// Send OTP to WhatsApp
await rembase.sendWhatsappOTP('+1234567890');
// Login with WhatsApp OTP
const user = await rembase.login(CredentialTypes.whatsapp('+1234567890', '123456'));Anonymous Authentication
// Login anonymously
const user = await rembase.login(CredentialTypes.anonymous());3. Cloud Functions
// Call a cloud function
if (rembase.currentUser) {
const result = await rembase.currentUser.callFunction('myFunction', 'param1', 'param2');
console.log('Function result:', result);
}4. User Management
// Check if user is logged in
if (rembase.currentUser) {
console.log('User ID:', rembase.currentUser.id);
console.log('User Email:', rembase.currentUser.email);
// Refresh access token
await rembase.currentUser.refreshAccessToken();
// Logout
rembase.currentUser.logout();
}5. Password Management
// Send password reset email
await rembase.sendPasswordResetEmail('[email protected]');
// Reset password with token
await rembase.resetPassword('reset-token', 'newpassword123');
// Reset password instantly (requires authentication)
await rembase.resetPasswordInstantly('oldpassword', 'newpassword123');6. Logging
// Log custom events
await rembase.log('user_action', true, 'user123', { action: 'click' }, { result: 'success' });API Reference
Initialization Functions
rembaseInitSync(appId, projectId, regionCode)
Initialize Rembase with your app credentials.
appId: Your Rembase app IDprojectId: Your Rembase project IDregionCode: Your region code (e.g., 'us', 'eu')
rembaseInitSelfHost(appId, selfHostUrl)
Initialize Rembase with a self-hosted instance.
appId: Your Rembase app IDselfHostUrl: Your self-hosted Rembase URL
rembaseInitSyncServer(appId, projectId, regionCode, userToken)
Initialize Rembase with a server-side user token.
appId: Your Rembase app IDprojectId: Your Rembase project IDregionCode: Your region codeuserToken: Server-side user token
Credential Types
CredentialTypes.email_password(email, password)
Create email/password credentials.
CredentialTypes.email_otp(email, otp)
Create email OTP credentials.
CredentialTypes.whatsapp(contact, otp)
Create WhatsApp OTP credentials.
CredentialTypes.anonymous()
Create anonymous credentials.
CredentialTypes.jwt(token)
Create JWT token credentials.
CredentialTypes.refreshCredential(id, token)
Create refresh token credentials.
RembaseApp Methods
login(credential)
Authenticate a user with the provided credentials.
registerUser(email, password)
Register a new user with email and password.
send_email_otp(email)
Send OTP to the specified email address.
sendWhatsappOTP(contact)
Send OTP to the specified WhatsApp contact.
resetPassword(token, password)
Reset password using a reset token.
resetPasswordInstantly(oldPassword, newPassword)
Reset password instantly (requires authentication).
sendPasswordResetEmail(email)
Send password reset email.
resendVerificationEmail(email)
Resend verification email.
log(name, success, user_id, request, response, error?, execution_time?)
Log custom events.
RembaseUser Methods
callFunction(functionName, ...args)
Call a cloud function.
refreshAccessToken()
Refresh the user's access token.
logout(redirectPath?, cookieRemoveFunction?)
Logout the current user.
Storage
The SDK uses @react-native-async-storage/async-storage for persistent storage of tokens and configuration. The storage is automatically managed by the SDK.
Error Handling
All methods that can fail will throw errors. Make sure to wrap them in try-catch blocks:
try {
const user = await rembase.login(CredentialTypes.email_password('[email protected]', 'password'));
console.log('Login successful:', user);
} catch (error) {
console.error('Login failed:', error.message);
}TypeScript Support
This SDK is written in TypeScript and provides full type definitions for all methods and types.
License
MIT
Support
For support and questions, please visit https://rembase.revtrance.com or open an issue on GitHub.
