본문으로 건너뛰기
InstaPlay
가이드 섹션

Player and sign-in: guests, accounts and sign-in from the game

On InstaPlay nobody has to sign in to play: from the first launch every player is a guest with cloud saves, a place on the leaderboards and a token for your own server. A player signs in to an account to keep progress on every device and under a chosen nickname. Since SDK 1.4 the game can offer sign-in itself: InstaPlay.player.login() opens the portal sign-in window over the game. The method reference is Player.

Guests and accounts

Guest Account
player.kind guest account
Cloud saves, leaderboards, analytics yes yes
Token for your server (getToken) yes, kind: guest yes, kind: account
Progress on other devices no — a guest is bound to this browser yes
Nickname and avatar guest nickname, portal identicon chosen in the portal profile

A player creates an account with Google, VK ID or Yandex ID (those configured on the portal) or by email with a one-time code. The first sign-in upgrades the guest in place: player.id, saves and scores stay the same, only kind changes. Signing in to an existing account (for example, one created on another device) gives a different player.id; if the guest has progress, the portal asks whether to move it to the account (merge rules as for saves: the newer wins, the best score is kept).

You do not need to talk a guest into signing in for the game to work: guest saves are in the cloud, not only in the browser. Signing in is a bonus for the player, not a required step.

Who is playing: player.get()

const env = await InstaPlay.init()
const me = await InstaPlay.player.get()
// { id: 'p3k9x2…', kind: 'guest', nickname: 'Swift Fox 48', avatar: null }
  • id is the player's pseudonym for your studio: the same in all your studio's games and public (it shows on leaderboards). Use it as a key on your server only when env.session === 'ok'.
  • kind is guest or account; nickname and avatar are for the game screen.
  • The game never gets the email, sign-in provider ids, cookies or account tokens.

Token for your own server

player.id is public, so to sign in to your own server the game takes a portal-signed token — InstaPlay.player.getToken() (SDK 1.1, a JWT for 10 minutes) — and exchanges it for a server session. Guests have a token too. Signature verification, claims and examples in Node.js, Ruby and Python — Player token for your server.

Sign-in from the game: player.login()

SDK 1.4. Opens the portal sign-in window over the game — the same one as the “Sign in” button in the portal header: Google, VK ID, Yandex ID (if configured on the portal) and email with a one-time code. The game sees neither the window nor the sign-in data — only the outcome.

InstaPlay.player.login(): Promise<LoginResult>

type LoginResult =
  | { status: 'signed_in'; player: PlayerInfo }
  | { status: 'already_signed_in'; player: PlayerInfo }
  | { status: 'cancelled' }

Rules:

  • Only on a player action. Call it in a click, tap or key handler — right away, before long awaits: the browser treats a gesture as active for only a few seconds. A call without a gesture (on a timer, after loading, at the end of a level without a press) is the gesture_required error.
  • At most 3 times a minute per frame, and not sooner than 10 s after the player closed the window without signing in; otherwise rate_limited with retryAfterMs.
  • One window at a time. A repeated call while the window is open returns the same promise — a double click does not open a second window.
  • Pause. While the window is open the game is paused: pause with { reason: 'overlay' }, then resume after it closes. On pause the SDK sends the save buffer immediately — nothing to add.
  • Time limit. A window left open for 15 minutes closes by itself — the outcome is cancelled.
  • Where it works. The login capability: InstaPlay.isSupported('login'). It is missing outside the portal (local and disabled modes) and in a preview. The old name authorize is the same thing: isSupported('authorize') === isSupported('login').

Outcomes

status What happened What the game does
signed_in, same player.id the guest became an account in place (first sign-in) keep playing: no restart, the same saves; player in the reply is already kind: 'account' — update the nickname and avatar
signed_in, different player.id the player signed in to an existing account nothing: playerChanging { reason: 'login' } follows, and in about 1.5 s the portal restarts the game under the account (below)
already_signed_in the player is already an account; no window was shown hide the sign-in button
cancelled the player closed the window (or it closed after 15 minutes) nothing; do not reopen the window on your own

After signed_in the SDK drops its token cache: the next getToken() returns a token with kind: account. If your server treats guests and accounts differently, get a new token and exchange it again.

Errors

An error is an InstaPlayError with a code field (errors and limits):

code When
not_supported no login capability: outside the portal, in a preview
unavailable the portal has no sign-in methods right now or the portal API is unavailable
gesture_required the call is not from a player action handler
rate_limited more than 3 calls a minute; retryAfterMs — when to retry
not_initialized a call before init
timeout the portal did not answer in 16 minutes

A “Save progress to an account” button

Show the button only to a guest and only where sign-in is available:

const button = document.getElementById('save-to-account')
let me = await InstaPlay.player.get()
button.hidden = !(InstaPlay.isSupported('login') && me.kind === 'guest')

async function signIn() {
  try {
    const result = await InstaPlay.player.login() // the first thing in the press handler
    if (result.status === 'cancelled') return // closed the window — do not insist
    button.hidden = true
    if (result.player.id !== me.id) return // another account — the portal restarts the game
    me = result.player // the guest became an account in place: keep playing
    hud.setPlayer(me.nickname, me.avatar)
  } catch (e) {
    if (!InstaPlay.isError(e)) throw e
    if (e.code === 'not_supported') button.hidden = true
    else if (e.code === 'rate_limited') showToast('Try again in a minute')
    else if (e.code === 'unavailable' || e.code === 'timeout') showToast('Sign-in is unavailable now')
    else console.warn('login', e.code) // gesture_required — not called from a press: a bug in the code
  }
}

button.addEventListener('click', signIn)

Offer sign-in after a level

A good place for the offer is the level results screen, when the player already has something to lose. The game shows its own screen with a “Sign in” button, and the portal window opens only on a press:

let offered = false

function onLevelComplete(level) {
  showLevelResults(level)
  if (offered || level < 3 || me.kind !== 'guest' || !InstaPlay.isSupported('login')) return
  offered = true // one offer per launch
  showOffer({
    text: 'Sign in to keep your progress on every device',
    onAccept: signIn, // the “Sign in” button press handler — from the example above
    onDecline: hideOffer,
  })
}

Do not open the sign-in window on your own — at start, on a timer, after a loss: such a call returns gesture_required, and frequent offers annoy players. A refusal is a normal outcome: the guest keeps playing with all cloud saves.

Player change: playerChanging

What happened What the game gets
A guest signed in from the game, first sign-in (upgrade in place) login() → signed_in; no playerChanging and no restart
A guest signed in from the game to an existing account login() → signed_in, then playerChanging { reason: 'login' }, a restart in about 1.5 s
Sign-in or sign-out in the portal header or in another tab playerChanging (login, logout, switch), a restart in about 1.5 s

In the ~1.5 s window before the restart the portal no longer accepts the previous player's calls: saves and leaderboards answer session_expired (the SDK already sent the cloud save buffer on the sign-in window pause). Send your data only to your own server — with the session it issued earlier: after a sign-in from the game the token cache is dropped, and the previous guest's token is gone in this window. After the restart the game starts under the new player; the previous guest pseudonym reaches your server in the merged claim of the account token (a guest became an account). Details — portal events.

Engines and the emulator

login is in engine wrappers 1.3.0 — Unity, Godot, Construct 3; in Phaser and PixiJS call InstaPlay.player.login() directly.

The method works in the instaplay dev emulator (CLI): it opens a “Sign-in from the game” window with the “Sign in as a test player” button (the player becomes an account in place — signed_in with the same player.id) and “Cancel” (cancelled). A player change with a restart — as when signing in to another account — comes from the player switch in the emulator panel (emulator).

Coming from CrazyGames

CrazyGames SDK v3 InstaPlay SDK
user.getUser() InstaPlay.player.get() — a guest is a player too, not null
user.getUserToken() InstaPlay.player.getToken() — guests have a token too
user.addAuthListener(fn) InstaPlay.on('playerChanging', fn) — a player change restarts the game; a sign-in from the game itself is the login() outcome
user.showAuthPrompt() InstaPlay.player.login()
user.isUserAccountAvailable InstaPlay.isSupported('login')

The main difference: on InstaPlay a guest is a full player. A guest has cloud saves, leaderboards and a server token, so signing in is optional and a guest needs no “sign in to save” screen — you can only offer to carry the progress to every device. Move your saves to cloud saves; everything else about porting a game is on the SDK page.