authentication-and-security-patterns

authentication-and-security-patterns is a cursor rule for Cursor from madebyaris/poinf-of-sales. It costs 0 tokens per session (2,998 once invoked), scanned A, original, MIT.

Reference patterns for authentication, security, and debugging in a React and Go point-of-sale system. Authentication controls who can access the system, while security protects its data and operations.

In plain words
What is it for?
Use it when building or debugging the system's login flow, API client authentication, token storage, user sign-out, and related security code.
Why use it?
It provides a consistent way to handle login tokens, authenticated API requests, sign-out, and common security concerns in this type of application.

Cursor rule for Cursor

Written for Cursor: installed under .cursor/.

Good fit Use it when building or debugging the system's login flow, API client authentication, token storage, user sign-out, and related security code.

Compare 6 cursor rules from other repositories ↓
Install with agentmods
npx agentmods add rules/madebyaris/poinf-of-sales/authentication-and-security-patterns
Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

Clone the repo
git clone --depth 1 https://github.com/madebyaris/poinf-of-sales

Made for: Cursor.

Wrote this? Show the measurements

A badge with what this costs and how it scanned, read live from this page, so it follows the numbers instead of freezing them. Markdown for a README, HTML for a documentation site or a project page.

agentmods badge for authentication-and-security-patterns

README.md
[![agentmods](https://agentmods.dev/badge/rules/madebyaris/poinf-of-sales/authentication-and-security-patterns/github.svg)](https://agentmods.dev/rules/madebyaris/poinf-of-sales/authentication-and-security-patterns)
Your own site
<a href="https://agentmods.dev/rules/madebyaris/poinf-of-sales/authentication-and-security-patterns"><img src="https://agentmods.dev/badge/rules/madebyaris/poinf-of-sales/authentication-and-security-patterns/github.svg" alt="Measured on agentmods" height="20"></a>

Or the 80×15 button, for a site that already has a row of RSS and ATOM ones. Only the verdict fits; the numbers stay here.

agentmods 80×15 button for authentication-and-security-patterns

Your own site · 80×15
<a href="https://agentmods.dev/rules/madebyaris/poinf-of-sales/authentication-and-security-patterns"><img src="https://agentmods.dev/badge/rules/madebyaris/poinf-of-sales/authentication-and-security-patterns.svg" alt="Reviewed on agentmods" width="80" height="20"></a>
Per session 0 Nothing until a file matches its globs; then the whole rule loads.
When invoked 2,998 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 1 finding. A grade says what 26 rules found in the file — not that it is safe.
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5.1 $0.00000 $0.02998
Opus 5 $0.00000 $0.01499
Sonnet 5 $0.00000 $0.00600
Haiku 4.5 $0.00000 $0.00300

Measured 11d ago against content hash db7a20e17e53, method: parsed. Prices are Anthropic first-party input rates as of 2026-09-11, from the pricing page.

Security

Grade A, and why

authentication-and-security-patterns scanned grade A with 1 finding against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured 11d ago.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Makes network callslowCapability

Not a fault in itself. Listed so you know the mod talks to something, and to what.

this.client = axios.create({
.cursor/rules/authentication-and-security-patterns.mdc · 450 lines

How it starts

The opening of the file, as written. The whole thing — 450 lines — stays where its author put it; the contents beside it link to each section on GitHub.

🔐 Authentication & Security Patterns

🚀 Essential Authentication Architecture

JWT-Based Authentication Flow

// Complete authentication workflow
class APIClient {
  constructor() {
    const apiUrl = import.meta.env?.VITE_API_URL || 'http://localhost:8080/api/v1';
    console.log('🔧 API Client baseURL:', apiUrl);
    
    this.client = axios.create({
      baseURL: apiUrl,
      timeout: 30000,
      headers: { 'Content-Type': 'application/json' }
    });

    // Auto-attach token from localStorage
    this.loadStoredAuth();
  }

  private loadStoredAuth(): void {
    const token = localStorage.getItem('pos_token');
    if (token) {
      this.client.defaults.headers.common['Authorization'] = `Bearer ${token}`;
    }
  }

  setAuthToken(token: string): void {
    localStorage.setItem('pos_token', token);
    this.client.defaults.headers.common['Authorization'] = `Bearer ${token}`;
  }

  clearAuth(): void {
    localStorage.removeItem('pos_token');
    localStorage.removeItem('pos_user');
    delete this.client.defaults.headers.common['Authorization'];
  }

  isAuthenticated(): boolean {
    return !!localStorage.getItem('pos_token');
  }
}

🏗️ React Authentication Components

Protected Route Pattern (Avoid Infinite Redirects)

function HomePage() {
  // ✅ ALL HOOKS AT TOP LEVEL - NEVER after returns
  const [user, setUser] = useState<User | null>(null);
  const [isLoadingAuth, setIsLoadingAuth] = useState(true); // Critical: Start true

  const { isLoading: isVerifying, error } = useQuery({
    queryKey: ['currentUser'],
    queryFn: () => apiClient.getCurrentUser(),
    enabled: false, // Control when to verify
    retry: 1,
  });

  // Load auth state from localStorage FIRST
  useEffect(() => {
    const loadAuthState = async () => {
      const token = localStorage.getItem('pos_token');
      const storedUser = localStorage.getItem('pos_user');
      
      console.log('🔍 Loading auth - token:', token ? 'exists' : 'missing');
      console.log('🔍 Loading auth - user:', storedUser ? 'exists' : 'missing');
      
      if (storedUser && token) {
        try {
          const parsedUser = JSON.parse(storedUser);
          setUser(parsedUser);
          console.log('✅ Auth loaded - user role:', parsedUser.role);
        } catch (error) {
          console.error('❌ Invalid stored auth data, clearing');
          apiClient.clearAuth();
        }
      }
      
      setIsLoadingAuth(false);
    };
    
    loadAuthState();
  }, []);

  // ✅ CRITICAL: Wait for localStorage loading before auth checks
  if (isLoadingAuth) {
    return <LoadingSpinner message="Loading authentication..." />;
  }

  // Only check auth AFTER loading is complete
  if (!apiClient.isAuthenticated() || !user) {
    console.log('🔄 Not authenticated, redirecting to login');
    return <Navigate to="/login" replace />;
  }

  // Render protected content with user context
  return <RoleBasedLayout user={user} />;
}

Read the full file on GitHub · 450 lines

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. 11d ago First seen · 450 lines · 2,998 tokens per session scan A db7a20e17e53

Subscribe to this mod's changes

authentication-and-security-patterns is a cursor rule published in the GitHub repository madebyaris/poinf-of-sales (142 stars, last pushed 1y ago), licensed MIT. It costs nothing until one of its globs matches a file; then it loads 2,998 tokens. A static security scan graded it A with 1 finding (makes network calls). No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-30.