phoenix-scopes
Installation
SKILL.md
Phoenix Scopes
Phoenix 1.8 introduced Scope as the new authentication primitive, replacing direct current_user access.
RULES — Follow these with no exceptions
- Use Scope structs instead of raw
current_user— scopes wrap the user and carry additional context such as roles, permissions, and tenant info - Use bracket access in templates —
assigns[:current_scope]prevents crashes when unauthenticated - Test both authenticated and unauthenticated states — scope-based auth has two distinct code paths
- Define
anonymous/0for the unauthenticated case — return a Scope withuser: nil - Always check
Scope.authenticated?/1before accessing.user— never assume scope is authenticated
End-to-End Workflow
Follow this sequence when implementing or migrating to scope-based authentication: