Huawei Account Kit (React Native)

Neha Jeswani
4 min readMar 5, 2021

--

HUAWEI Account Kit offers very simple, quick and secure sign in and authorization functionalities which help many developers to implement hassle free and quick sign in functionalities for applications.

HUAWEI Account Kit offers very simple, quick and secure sign in and authorization functionalities which help many developers to implement hassle free and quick sign in functionalities for applications.

HUAWEI Account Kit offers services on different parameters as

Quick and Standard

Massive user base and global services

Secure, reliable, and compliant with international standards

Quick sign-in to apps

Development Overview

Prerequisite

1. Must have a Huawei Developer Account

2. Must have a Huawei phone with HMS 4.0.0.300 or later

3. React Native environment with Android Studio, Node Js and Visual Studio code.

Major Dependencies

1. React Native CLI : 2.0.1

2. Gradle Version: 6.0.1

3. Gradle Plugin Version: 3.5.2

4. React Native Account Kit SDK : 5.0.0.300

5. React-native-hms-account kit gradle dependency

6. AGCP gradle dependency

Preparation

  1. Create an app or project in the Huawei app gallery connect, click My apps, as shown below.

Click on New app.

2. Provide the SHA Key and App Package name of the project in App Information Section and enable the required API.

Add the below information to create a new app and project

Once app is created, goto My projects

Click on the created project

Enable the AccountKit API

Put SHA signature generated using Android Studio

Download agc services file and paste it under App folder of the project.

3. Create a react native project, use the below command

“react-native init project name”

4. Download the React Native Account Kit SDK and paste it under Node Modules directory of React Native project.

Tips

1. Run below command under project directory using CLI if you cannot find node modules.

“npm install” & “npm link”

Integration

1. Configure android level build.gradle

Add to buildscript/repositories and allprojects/repositories

maven {url ‘http://developer.huawei.com/repo/'}

2. Configure app level build.gradle. (Add to dependencies)

Implementation project (“: react-native-hms-ads”)

3. Linking the HMS Account Kit Sdk.

Run below command in the project directory

react-native link react-native-hms-account

Adding permissions

Add below permissions to Android.manifest file.

<uses-permission android:name=”android.permission.INTERNET” />

<uses-permission android:name=”android.permission.ACCESS_NETWORK_STATE”/>

Development Process

Once sdk is integrated and ready to use, add following code to your App.js file which will import the API’s present.

Import the SDK

Sign In

Sign Out

Testing

Import the SDK

Add below line of code in the app.js file

import RNHMSAccount from “react-native-hms-account”;

Sign In

To sign in, create a signInData object and set the field values. Then invoke the signIn method of the HMSAccount module, setting the signInData object as the argument. If the sign in is successful, an AuthHuaweiId object will be returned, an exception object is returned otherwise.

Add below code on the “SIGN IN” button click

Sign Out

To sign out, invoke the signOut method of the HMSAccount module. The promise is resolved if the sign in is successful, is rejected otherwise.

Add below code on the “SIGN OUT” button click.

Testing

Run the below command to build the project

React-native run-android

Upon successful build, run the below command in the android directory of the project to create the signed apk.

gradlew assembleRelease

Results

References

https://developer.huawei.com/consumer/en/doc/development/HMS-Plugin-Guides/introduction-0000001050725712

Conclusion

Adding SignIn and SignOut functionalities seems easy.

--

--

No responses yet