Add social login feature on Unity games

Nbase
3 min readMar 1, 2024

The Nbase Unity SDK allows developers to quickly and effortlessly develop and embed various social login and authentication on their games.

Let’s take a look at the breakdown of the integration.

1. Install Nbase Unity SDK

🔗 Download from Nbase’s official GitHub repo

2. Configuration for Android Gradle

  1. Go to Project Settings > Player > Publishing Settings > Build > check boxes on Custom Main Gradle Template and Custom Gradle Properties Template.

2. Go to Assets > External Dependency Manager > Android Resolver > Settings.

Uncheck the boxes on Enable Auto-Resolution and Explode AARs.

3. Navigate to the Editor menu and open the file shown below. The file is crucial for the Nbase SDK, as it defines all of the dependency packages needed. To use additional functionalities, simply add those to the file to start using the modules on Android and iOS.

4. Find the social login provider you want to use from the list and insert its code.

Example) Add the code for the Google login

 <?xml version="1.0" encoding="UTF-8"?>
<dependencies>
<androidPackages>
// insert the code here //
<androidPackage spec="io.nbase:nbasesdk:3.0.41"/>
// Google login //
<androidPackage spec="io.nbase:nbase-adapter-provider-google:3.0.1"/>
</androidPackages>
<iosPods>
<iosPod name="Alamofire" version="5.8.1" minTargetSdk="9.0" />
<iosPod name="Socket.IO-Client-Swift" version="16.1.0" minTargetSdk="9.0" />
</iosPods>
</dependencies>

5. Click Assets > External Dependency Manager > Android Resolver > Force Resolve in order. Then, the library will be added only when it is automatically installed on the mainTemplate.gradle.

3. Integration

To use the SDK login functionality that operates when the login button is clicked, use the simple code below.


NBaseSDK.NBase.signIn(Provider.google.ToString(), (user, error) => {
if (error != null)
{
if(error.code == MEMBER_WITHDRAW) { // Account withdraw
Debug.Log(error.Message.ToString()); // Withdraw message
}
else if(error.code == APP_UPDATED) { // Forced app update
Debug.Log(error.Message.ToString()); // Update message
}
else if(error.code == MEMBER_BANNED) { // Access restriction
Debug.Log(error.Message.ToString()); // Restriction message
}
else {
Debug.Log(error.Message.ToString());
}
return;
}
}

❗️This will only work properly after completing all the necessary settings on console and the Nbase dashboard. For detailed guide about the console and dashboard settings, please visit Nbase docs.

✨ Nbase SDKs (Unity, iOS, Android, JS, Unreal Engine) are free to use until your app’s DAU reaches 50. So feel free to download and explore the features! ✨

Learn more about Nbase and the SDKs👇
https://www.nbase.io

https://www.linkedin.com/company/nbase-corp/

Twitter @NbaseCorp

--

--