Players and sign-in

Guest accounts that survive restarts, display names, and linking guests to email or Google.

On this page

Guest sign-in#

Call this once at startup. It restores the stored session (refreshing it when needed) or creates a new guest, so the same player keeps their progress.

C#
var signIn = await Majacloud.Auth.SignInAnonymouslyAsync();
if (signIn.Ok)
{
    var player = signIn.Value;
    Debug.Log(player.PlayerId + " " + player.DisplayName + " guest: " + player.IsGuest);
}
New guests are limited to 30 per network every 15 minutes, which stops scripted account creation.

Display names#

Guests get a generated name such as Guest 4821. Players can choose their own; leaderboards show it.

C#
var renamed = await Majacloud.Auth.SetDisplayNameAsync("Nova");
if (!renamed.Ok) Debug.Log(renamed.Error.Message); // e.g. Validation: too long

Linking opens a secure web page on your MAJACLOUD server where the player signs in or registers with email and password or Google. The guest's progress (scores, saves, wallet) moves to that account, and the game receives the new session — on any device.

C#
// Opens the sign-in page, waits for the player, then switches the session
var linked = await Majacloud.Auth.LinkAccountAsync(new MajacloudLinkOptions { ReturnUrl = "mygame://auth" });
if (linked.Ok) Debug.Log("Signed in as " + linked.Value.DisplayName);

// WebGL: browsers only open tabs from a click, so start first and open inside the handler
var flow = await Majacloud.Auth.StartLinkAsync(new MajacloudLinkOptions { OpenBrowser = false });
linkButton.onClick.AddListener(() => flow.Value.OpenInBrowser());
var result = await flow.Value.WaitForCompletionAsync();
  1. The SDK creates a one-time secret (PKCE) and starts a sign-in flow.
  2. The player finishes on the web page; the SDK polls until the flow completes.
  3. The SDK exchanges the flow for a session using the secret, so a stolen link is useless.
  4. Flows expire after 15 minutes (extended while the page is open).

Returning to the game#

Without a return URL the page tells players to go back to the game. To send them back automatically, add your custom URL scheme (for example mygame) under API keys ▸ Player sign-in return URLs and pass mygame://auth as the return URL.

Events#

React when the player changes, signs out or when the session can no longer be refreshed:

C#
Majacloud.Auth.PlayerChanged += player => nameLabel.text = player?.DisplayName;
Majacloud.Auth.SignedOut += () => ShowTitleScreen();
Majacloud.Auth.SessionExpired += () => ShowSignIn();

Sign out#

Signing out revokes the session on the server and forgets it on the device. The next sign-in creates a new guest.

C#
await Majacloud.Auth.SignOutAsync();   // revokes the session on the server
Majacloud.Auth.ClearLocalSession();   // or only forget it on this device

Read players from your server#

With the secret key your server can read any player, including email and wallet balances:

JavaScript
// Node.js, created with secretKey
const found = await admin.server.getPlayer('player_3f9c…');
if (found.ok) console.log(found.value.player.email, found.value.player.wallets);

In the dashboard#

The Players page lists every player with their sign-in method, scores, saves and wallet. From there you can rename or disable a player, sign them out everywhere, send a password reset link or delete them.

Search page titles, headings and text.

↑↓ to navigate ↵ to open Esc to close