# Account integration scenarios

Each rule has a reason and a way to check it before you submit. Terms are in the [glossary](https://docs.zokogames.com/getting-started/glossary).

Pick the scenario that matches your game. All of them must keep guests playing.

## 1. Your game has no accounts

Use the [data module](https://docs.zokogames.com/sdk/data) for saves. Nothing else is required. Showing the player's portal name in the HUD via `getUser()` is optional.

## 2. Use the ZokoGames profile

Use the portal identity as the account. Read `getUser()` for the name and avatar, and listen with `addAuthListener` for sign-ins. Offer `showAuthPrompt()` on a button, never automatically. Store progress with the data module or your backend keyed by the verified `userId`.

## 3. Your own backend, guests allowed (basic integration)

You run your own login and server saves.

- Guests must be able to play without creating an account.
- Remove or disable external login methods (social login buttons) in the portal build.
- Call `getUserToken()` on every launch, verify it [server-side](https://docs.zokogames.com/sdk/user#verifying-on-your-server), and use it to look up or create the account for that `userId`.
- If the call fails with `userNotAuthenticated`, let the player continue as a guest. Do not open the sign-in dialog on your own.

## 4. Your own backend, linked accounts (full integration)

Players who already have a game account can link it to their ZokoGames identity.

1. Player signs in to the portal (`showAuthPrompt`).
2. Your game verifies the token on the server.
3. If the `userId` is already linked, load that account.
4. If not, call `showAccountLinkPrompt()`. The call resolves to `{ response: "yes" | "no" }`. On `"yes"`, link the `userId` to the player's game account. On `"no"`, continue as a guest.
5. From then on the ZokoGames identity wins: log them in with it on every launch.

Guidance:

- Refresh the stored username and avatar when they change.
- Prefer linking to a new account over merging two accounts that both have progress.
- Never trust `__dangerousUserId` from the client. Use the token.

## Saving progress

Progress must be saved one of three ways: the data module, your own backend linked through the user module, or both. A game that loses progress when the tab closes will not pass full launch.

**Why:** players come back, and day-1 return is one of the basic-launch metrics; guests must always be able to play because sign-in is the player's choice. **Check before submitting:** run the game in the [Preview tool](https://www.zokogames.com/preview) as a guest and signed out, close the tab, reopen it and confirm progress survives. The Preview tool's checklist ticks **Data module used** when your game syncs; the **Preview and QA** tab of your game, which runs the game with your leaderboard settings, also has **Data module used for saves** and **A leaderboard score was submitted**. The reviewer's account items are: playable as a guest, progress saves and restores, and leaderboard scores submit and display. In local mode `getUserToken()` returns an unsigned test token that a correct verifier rejects, and `?token_response=logged_out` tests the guest path; see the [user module](https://docs.zokogames.com/sdk/user#tokens). See [environments](https://docs.zokogames.com/getting-started/environments) and [cloud saves](https://docs.zokogames.com/guides/cloud-saves).

## Next steps

- [Data (cloud save)](https://docs.zokogames.com/sdk/data)
- [Player accounts and your backend](https://docs.zokogames.com/guides/player-accounts)
