Skip to content

Signed-in players from your own login

On a hosted deployment everyone is a guest unless your site says who they are. Guests play fine, but a guest’s progress lives in one browser, and checkpoint saves (multiplayer.save: "checkpoint") are off for them. Tell the room who your signed-in player is, and their saves follow them to any device.

Pick one:

You use What you add Server code
Clerk, Auth0, Firebase Auth, Supabase Auth, Cognito, Keycloak, any OIDC sign-in your provider’s issuer on the deployment, and one line in your page none
your own login (sessions, no JWTs) a ticket URL on the deployment, and one route on your server one route

Either way the room checks the player before they join, nothing secret goes into your page, and a player’s id lives in this deployment only (it never matches tickcli.com accounts or another deployment’s players).

  1. In tickcli.com/account/keys, open your deployment’s Edit and set Sign-in provider to your provider’s issuer (and Audience if its tokens carry one). See the table below.
  2. Before the deployment’s script tag, tell it how to get the signed-in player’s token:
<script>
// the signed-in player's token from your provider, or null for a guest
window.tickcliAuth = async () => (await window.Clerk?.session?.getToken()) ?? null;
</script>
<script src="https://tickcli.com/c/dep_ab12cd34ef56.js" data-game="my-game"></script>

That is all. Before each connect the script calls tickcliAuth(), sends the token, and the room server checks it against your provider’s public keys (its JWKS, found from the issuer): signature, issuer, audience, expiry. The player’s id is the token’s sub; their name is its name (or preferred_username, nickname, the part of the email before @). If tickcliAuth() gives nothing, the visitor plays as a guest.

Provider Sign-in provider (issuer) Audience tickcliAuth returns
Clerk your Frontend API URL, e.g. https://clerk.mygame.example leave empty Clerk.session?.getToken()
Auth0 https://YOUR_TENANT.auth0.com/ (with the last /) your API identifier auth0.getTokenSilently()
Firebase Auth https://securetoken.google.com/YOUR_PROJECT_ID YOUR_PROJECT_ID getAuth().currentUser?.getIdToken()
Supabase Auth https://YOUR_REF.supabase.co/auth/v1 authenticated (await supabase.auth.getSession()).data.session?.access_token
Amazon Cognito https://cognito-idp.REGION.amazonaws.com/POOL_ID your app client id the ID token from your Amplify session

Only asymmetric signatures are accepted (RS256 and friends, ES256, EdDSA): a token signed with a shared secret cannot be checked by anyone else, so Supabase projects need its asymmetric JWT signing keys (new projects have them). The issuer must match the tokens’ iss exactly. A token that lives more than 24 hours is refused; providers’ usual lifetimes (1 minute to 1 hour) are fine, since a fresh one is asked for at every connect.

If your provider loads after the page, wait for it inside tickcliAuth (for example await Clerk.load()): the script waits for the promise.

Set Ticket URL on the deployment to a route on your own site, for example https://mygame.example/api/tickcli-ticket (https, on one of the deployment’s sites; http://localhost works for testing). The script asks it with your visitor’s cookies before each connect. The route checks your login and asks tickcli.com for a one-time ticket with your API key (keep the key on your server):

// Node (Express)
app.get("/api/tickcli-ticket", async (req, res) => {
const user = req.session?.user; // your own login
if (!user) return res.status(401).end(); // a guest
const r = await fetch(`https://tickcli.com/api/v1/deployments/${process.env.TICKCLI_DEP}/play-ticket`, {
method: "POST",
headers: { Authorization: `Bearer ${process.env.TICKCLI_KEY}`, "Content-Type": "application/json" },
body: JSON.stringify({ id: String(user.id), name: user.name }),
});
res.set("Cache-Control", "no-store").status(r.status).json(await r.json());
});
<?php // PHP: api/tickcli-ticket.php
session_start();
if (empty($_SESSION['user_id'])) { http_response_code(401); exit; }
$ch = curl_init('https://tickcli.com/api/v1/deployments/' . getenv('TICKCLI_DEP') . '/play-ticket');
curl_setopt_array($ch, [CURLOPT_POST => true, CURLOPT_RETURNTRANSFER => true,
CURLOPT_HTTPHEADER => ['Authorization: Bearer ' . getenv('TICKCLI_KEY'), 'Content-Type: application/json'],
CURLOPT_POSTFIELDS => json_encode(['id' => (string) $_SESSION['user_id'], 'name' => $_SESSION['user_name'] ?? 'Player'])]);
$body = curl_exec($ch);
http_response_code(curl_getinfo($ch, CURLINFO_HTTP_CODE));
header('Content-Type: application/json'); header('Cache-Control: no-store');
echo $body;

id is your player’s stable id (1-64 of letters, digits and _ . : @ -): the same id is the same player and the same saves. name is shown to the others (40 characters). The answer is { "ticket": "a....", "expiresIn": 30 }: a ticket works once, for 30 seconds, for this deployment only. Up to 600 a minute per key. If your page already has a token-getting function, window.tickcliAuth may return a ticket from your route as well.

g.saveState() is "ok" for the signed-in owner of the run and "sign_in" for a guest: show your own sign-in link there. Changes to the deployment’s sign-in settings apply to new connections at once (browsers may keep the script tag itself for up to 5 minutes).

Your own server instead of hosted rooms: pass your users as who: { seat: "u:<id>", guest: false } (see A Node app), or give createRemoteServer a deployment with auth: { issuer, audience } for the provider path above.