Skip to content

Auth

FRVR.auth authenticates the current player against FRVR’s backend — either with a FRVR account, a platform provider (Facebook, Google Play, Apple, …), or anonymously.

Auth is the gatekeeper for cross‑device features: cloud storage, tournaments, social, leaderboards, and shop all run through it.

FRVR.config.auth = {};   // let the current channel pick its provider

(No extra FRVR.init() call — you’ve already called it once during startup.)

The SDK auto‑logs in from:

  1. A cached token in storage (if still valid), or
  2. The channel’s native credentials (e.g. Facebook Instant session), or
  3. Anonymous sign‑in, if enabled.
FRVR.config.auth = { enableAnonymousLogin: true };
if (FRVR.auth.isLoggedIn()) {
  const token  = FRVR.auth.getAccessToken();  // JWT, or null if expired
  const frvrId = FRVR.auth.getFRVRID();       // FRVR user id
}

Tokens refresh themselves in the background around 60% of their TTL — you can treat getAccessToken() as always returning a fresh one when logged in.

Only needed if the channel doesn’t sign the user in automatically (typically web):

await FRVR.auth.loginToFRVR({
  platform: 'frvr',
  credentials: {
    email: 'user@example.com',
    password: 'hunter2',
  },
});

Or by provider credentials the channel gave you:

await FRVR.auth.loginToFRVR({
  platform: 'facebook-instant',
  credentials: {
    asid: '…',
    appId: '…',
    asidSignedRequest: '…',
  },
});

'frvr' and the other platform strings come from the Platform enum (Platform.FRVR, Platform.FACEBOOK_INSTANT, …), exported from the SDK package — they’re not on window.FRVR, so use the string literals here.

await FRVR.auth.registerOnFRVR(
  { email, password, firstName, lastName },
  /* ifConflictTryLogin = */ true
);

With ifConflictTryLogin = true, an existing‑account error automatically degrades to a login attempt.

await FRVR.auth.loginAsAnonymous();

Anonymous sessions still persist a stable ID. You can upgrade one to a real account later with registerOnFRVR.

if (FRVR.auth.isLogoutSupported()) {
  await FRVR.auth.logout();
}

Some channels don’t allow logout (the player is always signed in via the host app) — check first.

FRVR.auth.addStatusChangeListener(({ isLoggedIn, platform }) => {
  if (isLoggedIn) refreshPlayerUI();
  else            showLoggedOutState();
});

Fired on login, logout, and token refresh.

MethodPurpose
init()Auto‑login (called by FRVR.init).
isLoggedIn()Valid session present?
isLoggingIn()Login in progress?
getAccessToken()JWT for backend calls.
getFRVRID()Current user’s FRVR id.
isVerified()Email verified (FRVR accounts only).
getCurrentPlatform()Which provider signed in ('FRVR', 'facebook', …).
getAvailableLoginPlatforms()Other providers you could offer.
loginToFRVR(req)Explicit login.
loginAsAnonymous()Anonymous session.
registerOnFRVR(creds, ifConflictTryLogin?)Create account and log in.
logout()Clear session.
isLogoutSupported()Channel allows logout?
addStatusChangeListener(fn)Subscribe to session changes.