The player in the InstaPlay SDK
InstaPlay.player.get()
const player = await InstaPlay.player.get()
// { id: 'p3k9x2…', kind: 'guest', nickname: 'Swift Fox 48', avatar: null }
id— the player's pseudonym for your studio: stable across your studio's games and different for other studios. The real player id, cookies and tokens are never passed to the game.kind—guestoraccount(the player signed in on the portal with VK ID, Yandex ID, Google or email — in the portal header or from the game,player.login()below). The pseudonym does not change on the first sign-in: the guest's progress becomes the account's progress.nickname— the guest nickname, derived from the id, in the portal language; for a signed-in player — the nickname they chose in their profile. A chosen nickname is global (the same in every game — the player is warned); if none is chosen, the guest nickname for your studio is used.avatar—nullfor a guest: the portal draws an identicon itself. For an account with a chosen avatar — an image path on your game's origin:/_ip/avatars/v1/<key>.webp(CSPimg-src 'self'allows it). Players do not upload avatars — only portal presets.
// { id: 'p3k9x2…', kind: 'account', nickname: 'Foxy', avatar: '/_ip/avatars/v1/fox-03.webp' }
Email, sign-in provider ids, account cookies and tokens are never passed to the game.
InstaPlay.player.getToken()
SDK 1.1. A player token signed by the portal — for your own game server: player.id is public
(it is visible in leaderboards) and is not good enough to sign in to a server.
if (InstaPlay.isSupported('token')) {
const token = await InstaPlay.player.getToken() // JWT ES256, lives 10 minutes
await fetch('https://api.my-game.example/login', { method: 'POST', body: token })
}
- The token is a JWT (
typ: ip-player+jwt):subis the sameplayer.id,audis the game id,kind, lifetime 10 minutes. The game server verifies the signature with the portal keys athttps://instaplay.ru/.well-known/instaplay-jwks.json. - The SDK caches the token until a minute before it expires; repeated calls do not reach the portal.
- No
tokenfeature (local/disabledmodes, no session) —not_supported. - In a preview
audispreview:<game id>: a production server rejects such a token by itself.
InstaPlay.player.login()
SDK 1.4. The portal sign-in window over the game — the counterpart of CrazyGames
user.showAuthPrompt(): Google, VK ID, Yandex ID (if configured on the portal) and email with a one-time
code. Examples, patterns and the CrazyGames SDK mapping are in the
Player and sign-in guide.
InstaPlay.player.login(): Promise<LoginResult>
type LoginResult =
| { status: 'signed_in'; player: PlayerInfo } // signed in
| { status: 'already_signed_in'; player: PlayerInfo } // already an account, no window
| { status: 'cancelled' } // closed the window
loginButton.hidden = !(InstaPlay.isSupported('login') && me.kind === 'guest')
loginButton.addEventListener('click', async () => {
const result = await InstaPlay.player.login() // only in a player action handler
if (result.status !== 'cancelled') loginButton.hidden = true
})
- Only on a player gesture — in a click, tap or key handler, right away, before long
awaits. Otherwise — thegesture_requirederror. At most 3 times a minute and not within 10 s after the window was closed without signing in (rate_limited). - One window at a time: a repeated call while the window is open returns the same promise. A window
left open for 15 minutes closes by itself —
cancelled; the SDK waits 16 minutes for a reply (timeout). - Pause: while the window is open the game gets
pause { reason: 'overlay' }, thenresume; on pause the SDK sends the save buffer immediately. signed_in, sameplayer.id— the first sign-in: the guest became an account in place. The pseudonym and saves stay the same, the game goes on without a restart;playerin the reply is alreadykind: 'account'. ThegetToken()cache is dropped: the next token haskind: account.signed_in, differentplayer.id— the player signed in to an existing account (for example, from another device); the portal itself asks whether to move the guest's progress (the newer wins). Then the game getsplayerChanging { reason: 'login' }, and in about 1.5 s the portal restarts it under the account. In this window send data only to your own server, not tosaves.already_signed_in— the player is already an account, no window was shown.cancelled— the player closed the window.- Errors:
not_supported— nologincapability (local/disabledmodes, preview,isSupported('login') === false);unavailable— the portal has no sign-in methods right now or the API is unavailable;gesture_required,rate_limited,not_initialized,timeout(errors and limits). - The capability is
isSupported('login'); the old reserved nameauthorizeis its alias (it used to be alwaysfalse).
Signing in and out restarts the game
Signing in from the portal header navigates to the provider's page: before that the portal pauses
the game (pause with the overlay reason), the SDK sends unsaved data immediately, and the game
restarts after the sign-in. If the player signs in or out in another tab while this tab with the
game is open, the portal restarts the game too: the player has changed, and one player's progress must
not go to another player's cloud. The game starts again with the new player's data — no special
handling is needed. Only the first sign-in from the game itself (player.login() above) goes without a
restart.
SDK 1.1: about 1.5 s before the restart the game receives the playerChanging event (reason:
login, logout or switch) — send what you need to your own server in time (getToken
returns the cached token in this window). Portal saves are no longer available in this window. The
exception is a sign-in from the game to another account: after signed_in the token cache is already
dropped, and the previous guest's token is gone in this window — send data with the session your server
issued earlier.
A guest player is created on the first game launch; progress is stored on the server. If the browser
blocks cookies, every page load is a new guest who cannot see the previous guest's progress: the
cloud belongs to someone else, and the SDK save buffer on the game origin is bound to the player. A
buffer written by another guest is neither returned to the new one nor sent — the SDK moves it to
__ip:orphan:<key> (it lives only in this browser, for debugging the game). The game then starts
from scratch — this is expected, not data loss: the previous guest's progress is intact on the
server.