Authentication
Rembase is a cross platform backend development system that helps you create fast and secure backend that reduces your backend development time by 70%.
Prerequsite
Install and initialize the application. see getting started
Anonymous Login
Anonymous is one of the most easiest authentication method available in the market but should be used with causion as it is not a reliable type of authentication for most cases.
final RemBaseApp remBaseApp = RemBaseApp(
appId: <appId>,
);
Future<void> yourOwnLoginFunction() async {
// Create anonymous credentials
final CredentialTypes credential = CredentialTypes.anonymous();
// Attempt anonymous login
final response = await remBaseApp.anonymousLogin(credential);
response
.onSuccess((data) {
// Handle data (e.g., update UI or notify user)
})
.onError((error) {
// Handle error (e.g., show error message to the user)
});
}
Email password Login
To use email password login you must register and verify the user first.
Register
final response = await remBaseApp.registerUser(email, password);
response
.onSuccess((data) {
// Handle data (e.g., update UI or notify user)
})
.onError((error) {
// Handle error (e.g., show error message to the user)
});
upon successful registration an email will be sent to the user. You might want to prompt user to check their email and spam
To send verification email again use
final response = await remBaseApp.resendVerificationEmail(emailController.text);
response
.onSuccess((data) {
// Handle data (e.g., update UI or notify user)
})
.onError((error) {
// Handle error (e.g., show error message to the user)
});
A verification email will be sent to User.
Once the user is successfully registered you can continue with the Login
final credentials = CredentialTypes.emailPassword(
email: email,
password: password,
);
final response = await remBaseApp.login(credentials);
response
.onSuccess((data) {
// Handle data (e.g., update UI or save user info)
})
.onError((error) {
// Handle error (e.g., show error message to the user)
});
Email OTP Login
You can also sign-in user with thier email and OTP. Here's how you can do it.
Step1. Send the otp to the user's email
final response = await remBaseApp.sendEmailOtp(email);
response
.onSuccess((data) {
// Handle data (e.g., update UI or notify user)
})
.onError((error) {
// Handle error (e.g., show error message to the user)
});
Step2. You can use that OTP and the email to login to the User.
final CredentialTypes credentials = CredentialTypes.emailOtp(email, otp)
final response = await remBaseApp.login(credentials);
response
.onSuccess((data) {
// Handle data (e.g., update UI or notify user)
})
.onError((error) {
// Handle error (e.g., show error message to the user)
});
Note: If you are using your own email credentials you might want to prompt users to check their email also.
Google Login
Prerequsite
Steps to Set Up OAuth for google_sign_in
in Google Cloud Console
-
Create and Configure Project
- Go to Google Cloud Console (opens in a new tab).
- Create a new project, enable Google Identity Services API, and set up the OAuth consent screen (external/internal).
-
Create OAuth Credentials
- Go to APIs & Services > Credentials > Create Credentials > OAuth 2.0 Client ID.
- Select Application Type: Android.
- Add your app’s package name and SHA-1 key (generated using
myKey.jks
).
-
Generate
myKey.jks
File
Run the following command to generate the keystore file:keytool -genkey -v -keystore myKey.jks -keyalg RSA -keysize 2048 -validity 10000 -alias upload
Follow the prompts to set the alias, key password, and store password.
-
Add Keystore in
build.gradle
Update theandroid/app/build.gradle
file:android { signingConfigs { release { keyAlias 'upload' keyPassword 'your_password' storeFile file('myKey.jks') storePassword 'your_password' } } buildTypes { release { signingConfig signingConfigs.debug } } }
-
Download
google-services.json
- Add
google-services.json
(from Google Cloud Console) toandroid/app/
.
- Add
final response = await remBaseApp.googleLogin();
response
.onSuccess((data) {
// Handle data (e.g., update UI or save user info)
})
.onError((error) {
// Handle error (e.g., show error message to the user)
});
To use google login you must go to Google cloud console and create a client Id see video (opens in a new tab)
Phone Auth
phone auth requires two steps
step1. sending OTP
Please make sure the phone contains the country code eg. +1
final response = await remBaseApp.sendPhoneOtp(<phoneNumber>);
response
.onSuccess((data) {
// Handle data (e.g., update UI or notify user)
})
.onError((error) {
// Handle error (e.g., show error message to the user)
});
once the user recieves the OTP take the otp and call
final CredentialTypes credential = CredentialTypes.phone(<phoneNumber>, <OTP>);
final response = await remBaseApp.login(credential);
response
.onSuccess((data) {
// Handle data (e.g., update UI or notify user)
})
.onError((error) {
// Handle error (e.g., show error message to the user)
});
LogOut
use the code snippet below to log out user.
await RemBaseUser.logOut();
//your code