Skip to main content
The useAuthStore is a Pinia store that manages user authentication, role-based permissions, and user profile data in the 5Stack platform.

Overview

This store handles:
  • User authentication state
  • Role-based access control
  • Discord account linking status
  • User profile data management

Import

import { useAuthStore } from '~/stores/AuthStore';

Usage

const authStore = useAuthStore();

// Get current user
const currentUser = authStore.me;

// Check user role
if (authStore.isAdmin) {
  // Admin-only logic
}

// Check if user has required role
if (authStore.isRoleAbove(e_player_roles_enum.match_organizer)) {
  // User is match organizer or above
}

State

me
Ref<Player>
Current authenticated user object containing profile data, role, and settings.
hasDiscordLinked
Ref<boolean>
Indicates whether the user has linked their Discord account.

Methods

getMe()

Fetches and initializes the current user’s data, establishing GraphQL subscriptions for real-time updates.
async getMe(): Promise<boolean>
Returns: boolean - true if authentication succeeded, false otherwise Example:
const isAuthenticated = await authStore.getMe();

if (isAuthenticated) {
  console.log('User authenticated:', authStore.me.name);
}

isRoleAbove()

Checks if the current user’s role is at or above the specified role level.
isRoleAbove(role: e_player_roles_enum): boolean
role
e_player_roles_enum
required
The role to check against
Returns: boolean - true if user’s role is at or above the specified role Example:
if (authStore.isRoleAbove(e_player_roles_enum.tournament_organizer)) {
  // User can organize tournaments
}

Computed Properties

isUser
ComputedRef<boolean>
true if the user has the base user role.
isVerifiedUser
ComputedRef<boolean>
true if the user has the verified_user role.
isStreamer
ComputedRef<boolean>
true if the user has the streamer role.
isMatchOrganizer
ComputedRef<boolean>
true if the user has the match_organizer role.
isTournamentOrganizer
ComputedRef<boolean>
true if the user has the tournament_organizer role.
isAdmin
ComputedRef<boolean>
true if the user has the administrator role.

Role Hierarchy

The store defines the following role hierarchy (from lowest to highest):
  1. user - Base user
  2. verified_user - Verified user
  3. streamer - Content creator
  4. match_organizer - Can organize matches
  5. tournament_organizer - Can organize tournaments
  6. administrator - Full platform access

Real-time Subscriptions

When getMe() is called successfully, the store automatically:
  • Establishes WebSocket connection
  • Subscribes to user profile updates
  • Initializes match and tournament subscriptions based on role
  • Connects to the Socket.io server for real-time events

Example: Role-based Navigation

const authStore = useAuthStore();

const navigationItems = computed(() => {
  const items = [
    { label: 'Home', path: '/' },
    { label: 'Matches', path: '/matches' },
  ];

  if (authStore.isRoleAbove(e_player_roles_enum.match_organizer)) {
    items.push({ label: 'Manage Matches', path: '/manage/matches' });
  }

  if (authStore.isRoleAbove(e_player_roles_enum.tournament_organizer)) {
    items.push({ label: 'Manage Tournaments', path: '/manage/tournaments' });
  }

  if (authStore.isAdmin) {
    items.push({ label: 'Admin Panel', path: '/admin' });
  }

  return items;
});

Build docs developers (and LLMs) love