Profile Management Overview
Player profiles in the Moitribe SDK store essential information about authenticated players, including their name, contact details, profile images, and social connections. Profile data is automatically retrieved after successful authentication and can be updated at any time.
What is a Player Profile?
A player profile contains:
- Basic Information: Player name, unique ID, level, and title
- Contact Details: Email address and phone number (optional)
- Visual Assets: Profile icons, high-resolution images, and banner images
- Social Data: Friend lists and social connections
- Device Information: FCM ID for push notifications (optional)
Profile data is automatically populated when a player authenticates using OTP or social login. Guest players do not have persistent profiles.
Profile Lifecycle
1. Profile Creation
Profiles are created automatically during account creation:
// Profile is created when player creates account with OTP
MoitribeSDK('my-game-id', 'createWithOtp', {
emailid: 'player@example.com',
otp: '123456',
callback: (result) => {
if (result.success) {
// New profile created
console.log('Account created');
}
}
});
2. Profile Retrieval
After authentication, profile data is available through the loginCallback:
MoitribeSDK('my-game-id', 'init', {
loginCallback: (result) => {
if (result.success) {
// Access player profile
const profile = result.playerdata;
console.log('Welcome,', profile.name);
console.log('Player ID:', profile.id);
}
}
});
3. Profile Updates
Update profile information at any time:
MoitribeSDK('my-game-id', 'updateProfile', {
name: 'NewPlayerName',
emailid: 'newemail@example.com',
callback: (result) => {
if (result.success) {
// Profile updated
console.log('Profile updated successfully');
}
}
});
Profile Data Structure
A complete player profile includes these fields:
| Field | Type | Description |
|---|---|---|
id | string | Unique player identifier |
name | string | Player's display name |
title | string | Player's title or rank |
level | string | Player's current level |
profileicon | string | URL to profile icon image |
profilehiresimg | string | URL to high-resolution profile image |
bannerimgland | string | URL to landscape banner image |
bannerimgport | string | URL to portrait banner image |
friends | string[] | Array of friend player IDs |
See Profile Data Structure for detailed field descriptions and TypeScript type definitions.
Common Profile Operations
Display Player Information
Access profile data to display in your game UI:
MoitribeSDK('my-game-id', 'init', {
loginCallback: (result) => {
if (result.success) {
const profile = result.playerdata;
// Update UI with player info
document.getElementById('player-name').textContent = profile.name;
document.getElementById('player-level').textContent = profile.level;
document.getElementById('player-avatar').src = profile.profileicon;
}
}
});
Update Player Name
Allow players to change their display name:
function changePlayerName(newName) {
MoitribeSDK('my-game-id', 'updateProfile', {
name: newName,
callback: (result) => {
if (result.success) {
// Refresh profile data
console.log('Name updated to:', newName);
updateGameUI();
} else {
console.error('Failed to update name:', result.msg);
}
}
});
}
Update Profile Picture
Update the player's profile image:
function updateProfilePicture(imageUrl) {
MoitribeSDK('my-game-id', 'updateProfile', {
picture: imageUrl,
callback: (result) => {
if (result.success) {
console.log('Profile picture updated');
}
}
});
}
Profile Data Persistence
Profile data is:
- Server-Stored: Synchronized across all devices
- Automatically Updated: Changes are immediately reflected
- Session-Cached: Available throughout the game session
- Cross-Platform: Accessible from web, mobile, and desktop
Profile data is stored on Moitribe servers and automatically synced. You don't need to implement local storage for profile information.
Authentication and Profiles
Profile management is closely tied to authentication:
| Authentication Method | Profile Behavior |
|---|---|
| OTP Login | Full profile with user-provided information |
| Social Login | Profile pre-filled with social account data |
| Account Creation | New profile created with basic information |
| Guest Login | No persistent profile (local only) |
Profile Updates and Validation
Updateable Fields
You can update these profile fields:
name- Player's display nameemailid- Email addressphno- Phone numberpicture- Profile picture URLgfcmid- Firebase Cloud Messaging ID
Non-Updateable Fields
These fields are managed by the system:
id- Assigned at account creationlevel- Updated through gameplay progressiontitle- Updated through achievementsfriends- Modified through social features
Some fields like id, level, and title cannot be directly updated through updateProfile(). These are managed through other SDK features or gameplay progression.
Error Handling
Profile operations may fail for various reasons:
MoitribeSDK('my-game-id', 'updateProfile', {
name: 'NewName',
callback: (result) => {
if (result.success) {
console.log('Profile updated successfully');
} else {
// Handle different error scenarios
switch (result.statuscode) {
case 401:
console.error('Not authenticated');
redirectToLogin();
break;
case 400:
console.error('Invalid profile data:', result.msg);
break;
default:
console.error('Update failed:', result.msg);
}
}
}
});
Best Practices
1. Cache Profile Data
Store profile data locally during the game session to reduce API calls:
let currentPlayerProfile = null;
MoitribeSDK('my-game-id', 'init', {
loginCallback: (result) => {
if (result.success) {
currentPlayerProfile = result.playerdata;
displayProfile(currentPlayerProfile);
}
}
});
// Access cached profile throughout the game
function getPlayerName() {
return currentPlayerProfile?.name || 'Guest';
}
2. Validate Before Update
Validate profile data before sending update requests:
function updateProfile(profileData) {
// Validate name length
if (profileData.name && profileData.name.length < 3) {
showError('Name must be at least 3 characters');
return;
}
// Validate email format
if (profileData.emailid && !isValidEmail(profileData.emailid)) {
showError('Invalid email address');
return;
}
// Send update request
MoitribeSDK('my-game-id', 'updateProfile', {
...profileData,
callback: handleUpdateResult
});
}
3. Handle Update Responses
Always refresh your UI after successful profile updates:
MoitribeSDK('my-game-id', 'updateProfile', {
name: 'NewName',
callback: (result) => {
if (result.success) {
// Update cached profile data
if (result.playerdata) {
currentPlayerProfile = result.playerdata;
}
// Refresh UI
updateGameUI();
// Show success message
showSuccess('Profile updated successfully');
}
}
});
4. Provide User Feedback
Always inform players about profile operation status:
function updatePlayerProfile(data) {
showLoading('Updating profile...');
MoitribeSDK('my-game-id', 'updateProfile', {
...data,
callback: (result) => {
hideLoading();
if (result.success) {
showSuccess('Profile updated!');
} else {
showError('Failed to update profile: ' + result.msg);
}
}
});
}
Profile Privacy
The Moitribe SDK respects player privacy:
- Profile data is only shared with authorized games
- Players control what information is public
- Contact details are never exposed to other players
- Friend lists are managed through SDK features
Profile images and banners are stored on Moitribe CDN servers for fast, global access. Images are automatically optimized for different device sizes.
Next Steps
Learn more about profile management:
- Get Profile - Access current player profile data
- Update Profile - Modify player information
- Profile Data Structure - Detailed field reference
Related topics:
- Authentication Overview - How profiles are created
- Login with OTP - Authenticate to access profiles
- Social Login - Pre-filled profile data