auth-patterns

Implement safe Supabase auth patterns to prevent deadlocks and session hangs.

Updated Aug 27, 2026
One-click install
npx skills add https://github.com/vassovass/scl-v3 --skill auth-patterns-vassovass
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: auth-patterns
Source: https://github.com/vassovass/scl-v3/tree/main/.claude/skills/auth-patterns
Command: npx skills add https://github.com/vassovass/scl-v3 --skill auth-patterns-vassovass

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Supabase authentication can suffer from deadlocks and session hangs when using certain Auth APIs in web apps. This skill provides safe patterns to avoid these issues and keep authentication flows reliable.

Core Features & Use Cases

  • Safe API patterns: Prefer getUser on server routes and avoid getSession on the client to prevent deadlocks.
  • Client-side strategies: Use onAuthStateChange for initial sessions and cache the session where appropriate.
  • Robust fallbacks: Implement token validation, cookie-based fallbacks for long-running tasks, and proper session cleanup.

Quick Start

Implement onAuthStateChange in your client app, fetch user data with getUser in API routes, and avoid getSession on the client to prevent deadlocks.

Frequently Asked Questions about auth-patterns

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I avoid deadlocks in Supabase authentication on the client side?

Avoid deadlocks by using onAuthStateChange for initial session detection on the client and getUser on server routes instead of getSession on the client. This prevents blocking calls that can hang session state.

What's the difference between getUser and getSession in Supabase auth?

getUser fetches the authenticated user and is safe for server routes; getSession retrieves session data but can cause deadlocks on the client. Prefer getUser server-side and onAuthStateChange client-side for reliable authentication flows.

How do I implement onAuthStateChange to handle Supabase auth state safely?

Use onAuthStateChange to listen for auth state changes on the client, cache the session where appropriate, and pair it with getUser calls in API routes. This pattern avoids session hangs and ensures robust token handling across SSR and long-running tasks.

What auth patterns prevent session hangs across API routes and SSR?

Implement token validation, use cookie-based fallbacks for long-running tasks, ensure proper session cleanup, and separate client-side listeners (onAuthStateChange) from server-side user fetches (getUser) to maintain reliable auth across API routes and server-side rendering.

Why does getSession block in Supabase web applications?

getSession can deadlock on the client because it may wait for session refresh or validation states that conflict with concurrent auth operations. Using getUser server-side and onAuthStateChange client-side with explicit sequencing eliminates this blocking behavior.

Do I need external tools to implement safe Supabase auth patterns?

No. Safe Supabase auth patterns rely only on clear code examples, safe fallbacks, and explicit sequencing without external tools. Focus on proper API selection (getUser vs getSession), token handling, and cookie synchronization across your application.