Skip to main content

Ready for Production?

Learn how to transition from testing to production with proper service account setup.

Service Account Types

Service AccountRoleSecurityUse Case
Client-SideplayerLoginSafe to expose in appsLog in existing players with their federated_id
Server-SideplayerCreateKeep secret on serverCreate new players from your backend

Typical Onboarding Flow

1. Quick Testing (What you've been doing)

You copied the Client-Side API key + test player's federated_id → immediately works in your app.

This is perfect for getting started quickly, but not suitable for production with real users.

2. Production Setup

Now it's time to separate concerns:

Your Backend (Server-Side Service Account):

  • Use the Server-Side API key to create new players
  • This key stays secret on your backend
  • Creates players and returns federated_id

Your App (Client-Side Service Account):

  • Use the Client-Side API key for player login
  • This key is safe to embed in your app
  • Logs in players using their federated_id

Making the Transition

Until now, you've used the Client-Side Service Account for testing. Here's how to move to production:

Step 1: Create Players from Backend

Your backend should use the Server-Side Service Account to create players:

// Your backend server (Node.js/Express)
const response = await fetch('https://pug.stg.uglabs.app/api/players', {
method: 'POST',
headers: {
'Authorization': `Bearer ${SERVER_SIDE_API_KEY}`, // Server-Side key
'Content-Type': 'application/json'
},
body: JSON.stringify({
external_id: userEmail // Your unique identifier
})
});

const { federated_id } = await response.json();

// Store federated_id in your database
await db.users.create({ email: userEmail, federatedId: federated_id });

Step 2: Login from Your App

Your app uses the Client-Side Service Account + the user's federated_id to login:

// Your app (client-side)
const response = await fetch('https://pug.stg.uglabs.app/api/auth/login', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
api_key: CLIENT_SIDE_API_KEY, // Safe to embed
federated_id: federatedId // From your backend
})
});

const { access_token } = await response.json();

Complete Production Flow

Security Checklist

Before going to production, verify:

  • Server-Side API key is stored securely on your backend (not in client code)
  • Client-Side API key is embedded in your app
  • Players are created only from your backend using Server-Side key
  • Federated IDs are stored securely in your database
  • Your app logs in players using Client-Side key + federated_id
  • API keys are different for dev/staging/production environments
  • You have error handling for player creation and authentication

Next Steps