> ## Documentation Index
> Fetch the complete documentation index at: https://docs.gamavas.fun/llms.txt
> Use this file to discover all available pages before exploring further.

# Web

> Gamavas Pass for any web game: one script, a button element, and a small JavaScript client.

The web SDK is a single script, with no build step and no dependencies. It works with any framework, or none: Phaser, PixiJS, Three.js, plain canvas, React and more.

```html theme={"theme":{"light":"github-light","dark":"github-dark"}}
<script src="https://gamavas.fun/sdk/pass.js"></script>
```

Load it in your page's `<head>`, before anything heavy. The sign-in popup comes back to this page, and the script closes it quickly.

## Connect your game

At [developer.gamavas.fun](https://developer.gamavas.fun), connect your game listing to get a **client ID**, and add the page your game runs on under **Where sign-in returns**, for example `https://your-game.example/`. See [How sign-in works](https://docs.gamavas.fun/pass/how-sign-in-works.md).

## The button

```html theme={"theme":{"light":"github-light","dark":"github-dark"}}
<gamavas-signin client-id="YOUR_CLIENT_ID" theme="dark"></gamavas-signin>
```

It fires `gamavas-signin` when a player signs in, and `gamavas-error` if sign-in fails:

```js theme={"theme":{"light":"github-light","dark":"github-dark"}}
document.addEventListener("gamavas-signin", (event) => {
  const { player, pass } = event.detail; // pass: the client below
  startGame(player);
});
document.addEventListener("gamavas-error", (event) => {
  console.log(event.detail.error.code); // "popup_closed", "access_denied", …
});
```

A returning player sees **Continue as @handle** and signs in with one click. Style it with `theme`, `size`, `shape`, `text`, `width` and `color` (see [Branding](https://docs.gamavas.fun/pass/branding.md)), and add `email` to ask for their email.

## The client

For your own button or more control:

```js theme={"theme":{"light":"github-light","dark":"github-dark"}}
const pass = GamavasPass.create({ clientId: "YOUR_CLIENT_ID" });

await pass.ready;                 // finishes a sign-in that came back to this page
pass.user;                        // the signed-in player, or null
pass.onChange((player) => {});    // signed in or out

button.onclick = async () => {
  const player = await pass.signIn();      // from a click; or signIn({ email: true })
};
await pass.signOut();             // signs out of your game, not of Gamavas
```

Or render the button yourself:

```js theme={"theme":{"light":"github-light","dark":"github-dark"}}
GamavasPass.renderButton(pass, document.querySelector("#signin"), {
  theme: "light",
  size: "large",
  onSignIn: (player) => startGame(player),
  onError: (error) => console.log(error.code),
});
```

## Achievements, progress and selling

```js theme={"theme":{"light":"github-light","dark":"github-dark"}}
await pass.unlock("first-win");               // { newlyUnlocked, xpAwarded, achievement }
await pass.unlock("secret", { notify: false }); // without Gamavas's notice
await pass.achievements();                    // [{ key, name, description, iconUrl, xp, unlocked, unlockedAt }]
await pass.progress();                        // { xp, level, title, toNextLevel }

if (!(await pass.owns())) await pass.purchase(); // checkout popup: call from a click
```

## Your server

```js theme={"theme":{"light":"github-light","dark":"github-dark"}}
const token = await pass.getAccessToken(); // null when signed out
```

Send it to your server and verify it there with [`@gamavas/pass-server`](https://docs.gamavas.fun/sdks/server).

## Options

```js theme={"theme":{"light":"github-light","dark":"github-dark"}}
GamavasPass.create({
  clientId: "YOUR_CLIENT_ID",
  redirectUri: "https://your-game.example/", // default: this page
  analytics: true,  // play time for your Analytics page; never earns XP
  test: false,      // test purchases for you and your testers; off before you ship
});
```

The script talks to the Gamavas it was loaded from, so `https://staging.gamavas.fun/sdk/pass.js` uses staging.

## Errors

Rejected promises carry a `GamavasPassError` with a `code` and a `message`:

| Code | When |
| - | - |
| `popup_closed` | The player closed the popup |
| `access_denied` | The player declined to connect your game |
| `popup_blocked` | The browser blocked the checkout popup |
| `signed_out` | The call needs a signed-in player |
| `forbidden`, `not_found`, `rate_limited`, `bad_request` | From the API, with Gamavas's explanation |


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.