The Aplauso API uses Firebase Authentication ID tokens as bearer tokens. Most endpoints require a valid token; a few guest-facing endpoints (such as creating a tip from a kiosk) are publicly accessible.

Getting a Token

From a Firebase Client SDK (frontend apps)

import { getAuth } from "firebase/auth";

const auth = getAuth();
const user = auth.currentUser;
if (user) {
  const idToken = await user.getIdToken();
  // idToken is a signed JWT string
}

Tokens expire after 1 hour. The Firebase SDK refreshes them automatically. Always call getIdToken() immediately before each request rather than caching the result.

From the Firebase Admin SDK (server-side)

import admin from "firebase-admin";

// After initializing the Admin SDK with your service account:
const customToken = await admin.auth().createCustomToken(uid);
// Exchange the custom token for an ID token using the REST API

For server-to-server calls, use a service account with Firebase Admin SDK and create a custom token, then exchange it for an ID token via the Firebase Auth REST API.

Sending the Token

Include the token in the Authorization header of every request:

Authorization: Bearer <idToken>

Example:

GET /v2/analytics?type=employee&employeeId=abc123&environment=live
Authorization: Bearer eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9...

Which Endpoints Require Auth

Auth RequiredEndpoints
Always requiredWallet, Dividends (PATCH), Employees (POST), Properties, Insights, Admin
Optional (enriches data if provided)Tips (POST/GET), Ratings (POST/GET), Visits (POST), Guests (GET)
Never requiredStripe publishable key, Monitoring health check

When a token is provided on optional endpoints, the createdBy field on the created record is set to the authenticated user's UID.

Roles and Permissions

Every authenticated user has a numeric role stored in their Firestore user document:

RoleValueTypical Capabilities
Employee10Read own tips/ratings/wallet; update own profile
Front Desk20Employee + limited team visibility
Manager30Front Desk + create invites, view team analytics
Outlet Admin40Manage outlet-scoped employees and analytics
Department Admin50Manage department-scoped data
Property Admin60Full property management, Stripe billing, all property analytics
Regional Admin70Multi-property management
System Admin100Full platform access

The role is validated server-side. Attempting to access a resource outside your role scope returns 403 Forbidden.

Scope Validation

In addition to role level, the API validates that the authenticated user has access to the specific organization, property, or department being queried. For example:

  • A PropertyAdmin at Property A cannot read data for Property B.
  • An Employee can only read their own tip and dividend records.

Pass the correct propertyId or organizationId in your requests and ensure your token belongs to a user with the appropriate role at that scope.

Token Errors

ErrorCauseFix
401 UnauthenticatedNo or malformed Authorization headerInclude Bearer <idToken> header
401 Token expiredID token older than 1 hourCall user.getIdToken(true) to force refresh
403 ForbiddenValid token but insufficient roleUse an account with the required role