Skip to content

User Module

This page explains how to integrate the Playol SDK user system, retrieve platform-injected user data, listen for changes, and properly manage player identity and data binding.

The Playol SDK includes a robust built-in user module that allows developers to obtain platform-level identity, avatar, nickname, and user type without building their own registration or login system. This user identity is automatically linked to game data such as save progress, items, leaderboards, and more.


📌 1. User Info Structure

After the Playol SDK is initialized, user data will be automatically injected and mounted to window.playolSDK.user.userInfo. The structure is as follows:

FieldTypeDescription
userIdstringUnique user ID (generated by platform, globally unique)
userNamestringUser nickname (may be empty, fallback handling recommended)
avatarstringUser avatar URL, can be used for display
sexnumberGender: 0 = Male, 1 = Female, 2 = Unknown
userTypenumberUser type: 0 = Guest, 1 = Registered

Example:

json
{
  "userId": "231175897226391552",
  "userName": "QEkuj",
  "sex": 0,
  "avatar": "https://static.playol.com/upload/userAvatarCover/avatar_1.png",
  "userType": 1
}

⚠️ Note: Some fields may be empty or use default values. Always implement proper fallback handling in UI rendering.


📥 2. How to Get User Info

As part of the game runtime environment, Playol SDK provides two methods for accessing the current player’s data:

✅ Method 1: Read Cached Variable

js
const userInfo = window.playolSDK.user.userInfo
console.log(userInfo)
  • This variable is automatically populated after SDK loads;
  • It also updates in real-time when the platform user changes.

✅ Method 2: Fetch Latest Data Asynchronously

js
// Promise style
window.playolSDK.user.getUserInfo().then(userInfo => {
  console.log(userInfo)
})

// Async/Await style
const userInfo = await window.playolSDK.user.getUserInfo()
console.log(userInfo)
  • Retrieves the latest user info from the platform;
  • The result also updates the cached user.userInfo variable.

📡 3. Listen for User Info Changes

When users switch accounts, log out, or their identity changes, the SDK will automatically trigger any registered listeners:

js
const handleUserChange = (userInfo) => {
  console.log("User info updated:", userInfo)
}

// Add listener
window.playolSDK.user.onChange(handleUserChange)

// Remove listener
window.playolSDK.user.removeChange(handleUserChange)

✅ It is recommended to register listeners after the game is fully loaded. If your game has multiple scenes or “re-enter” logic, be sure to call removeChange() at the appropriate time to avoid memory leaks or state conflicts.


🧾 4. User Type Explanation

userTypeDescriptionPermissions
0GuestCan try the game, but cannot make payments or sync assets
1Registered UserFull access to payments, ads, data sync, leaderboard, etc.

⚠️ Guest users can be guided to register through the platform. The SDK will support upgrade logic in future versions.


ScenarioRecommended Action
Game first launchUse getUserInfo() to fetch and cache user identity
Displaying user name/avatarUse user.userInfo.userName and avatar fields
Bind data/items to userUse userId as player key
Cross-device syncuserId is globally unique and consistent
Multi-instance / iframe modeUse onChange() to detect identity changes
Detect guest modeCheck user.userInfo.userType === 0

📦 6. FAQ

Q: userInfo is undefined or empty?

A: Ensure the SDK has been loaded and initSDKParam() is executed before accessing user info. Prefer getUserInfo() for a reliable fetch.

Q: Can guest users use ads or payment?

A: Not recommended. The platform may restrict such features for guest accounts. Guide users to register before using advanced features.

Q: Can users switch accounts?

A: Yes. The platform supports account switching. The SDK will automatically trigger the registered change listeners—no additional handling required.


👉 Quick Start | Payment Module | Data Module | Invite Module

Released under the MIT License