How to set up social login on Android devices
In mobile applications, you can implement social login by opening an authorization form inside the application. To do this, connect the native Xsolla SDK for Android to the Cocos Creator project. Using this library, you can open a social network authorization form in a custom WebView and receive a user token if login succeeds. In this case, the user does not need to leave the mobile application.
To add authorization through social networks in mobile applications:
- Connect native Xsolla SDK for Android to your project.
- Start authorization and processing of its results:
- Implement a UI for social login in your application (for example, the
Sign in with Google button on the login page). - In accordance with the logic of the application, implement a call of the
authSocial
native method. This method takes the name of the social network as a parameter.
- Implement a UI for social login in your application (for example, the
Example of starting social login:
Copy
- typescript
NativeUtil.authSocial(socialNetworkName);
- On the Cocos Creator side, subscribe to the successful authorization event. This event is generated at the scene level by native Activity that handles the authorization result. Once authorization is successful, call the
handleSuccessfulSocialAuth
handler method, which takes an object with the user’s token. This object can be used to further work with the Xsolla API.
- On the Cocos Creator side, subscribe to the successful authorization event. This event is generated at the scene level by native Activity that handles the authorization result. Once authorization is successful, call the
Subscription example:
Copy
- typescript
director.getScene().on(Events.SOCIAL_AUTH_SUCCESS, this.handleSuccessfulSocialAuth, this );
Note
From native scripts, the callback methods in Cocos Creator should be called from the game thread.
- Subscribe to login error and login cancellation events with a call to the necessary handler methods.
Was this article helpful?
Thank you for your feedback!
We’ll review your message and use it to help us improve your experience.Rate this page
Rate this page
Don’t want to answer
Thank you for your feedback!
Found a typo or other text error? Select the text and press Ctrl+Enter.