Skip to main content

Player Identifiers

Server-side utilities for working with FiveM player identifiers.

Overview

FiveM players have multiple identifiers from different authentication providers. This module provides type-safe access to parse and query these identifiers.

Identifier Format

Identifiers follow the pattern type:value:

TypeExampleSource
licenselicense:abc123def456Rockstar license
steamsteam:110000102345678Steam ID
discorddiscord:123456789012345678Discord ID
xblxbl:2535123456789Xbox Live
fivemfivem:12345FiveM account

Usage

"use server";

import {
collectPlayerIdentifiers,
getPrimaryLicense
} from "@core/player";

// Get all identifiers
const identifiers = collectPlayerIdentifiers(playerId);
// Returns: [{ type: "license", value: "abc...", raw: "license:abc..." }, ...]

// Get primary license (used for persistence)
const license = getPrimaryLicense(playerId);
if (license) {
await db.collection("players").findOne({ license });
}

Common Patterns

Player Profile Lookup

@Server
async getPlayerProfile(ctx: EventContext<[]>): Promise<Profile | null> {
const license = getPrimaryLicense(ctx.source);
if (!license) return null;

return await playerRepository.findByLicense(license);
}

Multi-Identifier Matching

function findPlayerByAnyIdentifier(identifiers: PlayerIdentifier[]) {
return db.collection("players").findOne({
$or: identifiers.map(id => ({ [`identifiers.${id.type}`]: id.value }))
});
}

Best Practices

  1. Use license as primary key - Most reliable identifier
  2. Store multiple identifiers - For account linking and recovery
  3. Handle missing identifiers - Not all players have all types
  4. Server-side only - Identifiers are available on server