3JS Games
Browse documentation

Guide

Local fallback

Preserve standalone play while using authenticated cloud storage when the platform integration is available.

  • Use cloud storage when available.
  • Handle AUTH_REQUIRED explicitly; availability does not prove authentication.
  • Optionally retain an existing localStorage fallback.
  • Do not silently overwrite a newer local save with older cloud data.
  • Keep merge and conflict behavior explicit; it is outside the current platform contract.
  • Never add direct Supabase access to an uploaded game.
async function saveProgress(value) {
  if (!ThreeJSGames?.storage?.isAvailable()) {
    localStorage.setItem("savegame", JSON.stringify(value));
    return;
  }
  try {
    await ThreeJSGames.storage.set("savegame", value);
  } catch (error) {
    if (error.code !== "AUTH_REQUIRED") throw error;
    localStorage.setItem("savegame", JSON.stringify(value));
  }
}