velven
Docs
Menu

Sign players in

A player signed in to Velven is signed in to your space too, with no consent screen and no prompt on load. A guest is asked only when they press a button of yours.

View guide as Markdown

Know who is playing

After ready(), Velven.user holds the signed-in player, or null for a guest. Use it for display: a name on the title screen, an avatar beside a score.

JavaScript
// Registered before ready(), it runs on every sign-in: the one known at ready(), and any later one.const stop = Velven.onAuth((user) => showName(user.handle)); // stop() to stop listeningconst environment = await Velven.ready(); // "velven" | "site" | "local"Velven.user; // { id, handle, avatar } or null

ready() resolves once and never rejects. It usually settles in under a second; the timing is in the reference.

Ask a guest to sign in

Call signIn() from a button. Inside Velven, a guest sees Velven's sign-in card over your space and signs in without your page reloading. The promise resolves when they have signed in, or chosen to stay a guest.

JavaScript
button.addEventListener("click", async () => {  const result = await Velven.signIn();  if (result.ok) showName(result.user.handle); // also result.token and result.expiresAt  else console.log(result.error);});

A signIn() call that fails resolves with one of these codes:

Code
signed_out
Meaning
The player chose to stay a guest or left the card open for 10 minutes, or the call was silent and nobody is signed in.
Code
unavailable
Meaning
Not inside Velven, or the space is not published with a verified owner.
Code
rate_limited
Meaning
More than 12 sign-in requests in a minute from this page.
Code
failed
Meaning
Velven did not answer.
Code
cancelled
Meaning
You cancelled the request with an AbortSignal.

Check without showing anything

signIn({ silent: true }) never shows the card. It resolves with the token when the player is signed in, and signed_out otherwise. Use it before a call that needs the token, or to recover when a session ends.

JavaScript
const quiet = await Velven.signIn({ silent: true });

Cancel a sign-in request

Pass an AbortSignal to bring the card down when your own UI moves on, for example when your menu closes. The call resolves cancelled, which counts as the player staying a guest.

JavaScript
const controller = new AbortController();const asked = Velven.signIn({ signal: controller.signal });controller.abort(); // the card comes down; asked resolves "cancelled"

When the card shows

The card shows only when a player could have asked for it. These rules keep it from nagging:

  • Ask from a button, or at the end of a run the player chose to finish. Never ask on load.
  • Within 5 seconds of a player choosing to stay a guest, a plain signIn() resolves signed_out without the card, since no click of theirs could have asked for it.
  • Once a player has stayed a guest twice on one page load, the card stops coming back and every plain signIn() resolves signed_out.
  • A sign-in is cached. A token lasts 1 hour. signIn answers from memory until the token has under a minute left, then asks Velven again.

When a session ends

A player can sign out in another tab mid-game. The next call that answers signed_out clears the cached token and sets Velven.user to null. Try signIn({ silent: true }) once; if that answers signed_out too, show your sign-in button again.

Requirements

Sign-in needs a listed space, played inside Velven:

  • Only a published space with a verified owner can sign players in. An unclaimed space answers unavailable until its creator claims it.
  • Sign-in works inside Velven only. On your own site signIn answers unavailable, so a space with accounts of its own keeps using them there.

Note: Is your space also embedded somewhere else, such as another game portal or a blog? There the SDK waits up to 7 seconds for Velven before it settles on site. Shorten the wait with data-probe-timeout="3000" on the script tag. The floor is 3 seconds, since inside Velven the page around your space can take that long to start on a slow phone.

The token

The token is for your own server, to prove who scored on a server board. A space without a backend never needs it.

Warning: The SDK keeps the token in memory and never writes it to storage. But Velven is a global, so any script on your page can call signIn({ silent: true }) and read it. It opens only your own boards, and only together with your secret; still, keep third-party scripts off a page that handles it.