SDKs
flutter-sdk
Authentication

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.

how to verify token?

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

  1. Create and Configure Project

  2. 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).
  3. 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.

  4. Add Keystore in build.gradle
    Update the android/app/build.gradle file:

    android {
        signingConfigs {
            release {
                keyAlias 'upload'
                keyPassword 'your_password'
                storeFile file('myKey.jks')
                storePassword 'your_password'
            }
        }
        buildTypes {
            release {
                signingConfig signingConfigs.debug
            }
        }
    }
  5. Download google-services.json

    • Add google-services.json (from Google Cloud Console) to android/app/.

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