Skip to content

User

The User module provides the ability to retrieve information about the currently logged-in player and the Token. If your game allows full gameplay without login, you do not need to use this module; otherwise, you must call the relevant interfaces to implement the required functionality.

After reading the section related to your game engine on the JOGOS_SDK Introduction page, you can use the relevant features as follows:

javascript
window.JOGOS_SDK.user;

Retrieve Current User Information

You can retrieve the current player's information using the following methods:

javascript
try {
  const user = await window.JOGOS_SDK.user.getUser();
  console.log('Get user result', user);
} catch (err) {
  // Handle exceptions
  console.error(err);
}

If the current player is not registered or logged in, the system will automatically open a login/registration dialog, requiring the user to register or log in successfully before continuing the game; otherwise, it will return a 401 Unauthorized, please log in again exception.

If the current player's account has been frozen or deleted, corresponding exception information will also be returned.

The structure of the successfully returned player object is as follows:

typescript
// User information
export interface UserInfo {
  // User Id
  userId: string;
  // Username
  username: string;
  // Avatar URL
  profilePictureUrl: string;
  // Game Id
  gameId: number;
}

The username in JOGOS_SDK must be 6–20 characters long and may contain letters, numbers, periods, and underscores.

Note: Multi-character games under a single account

The UserId of JOGOS_SDK corresponds one-to-one with the player account; if your game allows creating multiple game characters or switching characters across multiple servers, your server must handle this logic to prevent players from losing characters or being unable to switch.

Retrieve User Token (requires your game server to assist integration)

  • If you have a server, integration is required!
  • The user token contains information about the currently logged-in player. You need to send it to your server, where you verify/decode it to extract relevant information and bind it to your user system, ensuring the security of user data during this process.

Your client can retrieve the user token using the following methods:

javascript
try {
  const token = await window.JOGOS_SDK.user.getUserToken();
  console.log('Get token result', token);
} catch (err) {
  // Handle exceptions
  console.error(err);
}

The token is valid for 1 hour. We recommend that you do not store the token and always call this method whenever a token is needed.

If the current player is not registered or logged in, the system will automatically open a login/registration dialog, requiring the user to register or log in successfully before continuing the game; otherwise, it will return a 401 Unauthorized, please log in again exception.

If the current player's account has been frozen or deleted, corresponding exception information will also be returned.

The returned token can be decoded and tested at jwt.io.

The successfully returned token information contains the following JSON data:

json
{
  "jti": "1899405772252258304",
  "sub": "{\"profilePictureUrl\":\"a33bf366e34d48e984a094fc923d7b06.png\",\"gameId\":\"1\",\"profileDefaultAvatar\":\"default-avatar.png\",\"userId\":\"88E1B72FED537C6943C85C28F639BE0B\",\"username\":\"55895999999999999999\"}",
  "iss": "com:jogos:sdk",
  "iat": 1741688600,
  "exp": 1745288600
}
Do not decrypt the token on the client
Please do not decrypt the user token on the client; doing so is insecure. The token must be handled by your server.

When you need to authenticate requests with your server, you should send the token to your server, then decode and verify it. You can use this User Token Public Key https://www.jogos.com/publicKey.json to verify the token. We recommend that you fetch the key every time you verify the token, as it may change.

Next step: verification, handled by the server

For server-related APIs, please refer to the Server Integration API page.

Local Testing

During local testing, the User module interfaces simply return mock data.