@subject. A subject is the authenticated caller. You decide which entity represents a subject, which field identifies it, and which role paths grant permissions.
Subjects and Identity Fields
Mark an entity withsubject when records of that entity can authenticate. Add identity <fieldName> to choose the login identifier field.
The identity field must exist on the entity. SLang also includes @id as an identity field internally, so identity email means the runtime can connect a token subject back to the persisted user row.
Getting the User Entity
Use@subject.entity when action logic needs the persisted row for the authenticated subject.
Common uses:
- Return the current user from
GET /me. - Update profile fields on the authenticated user.
- Compare ownership with
where owner == @subject.entity.
owner := @subject.entity or owner := @subject when the relation field points at the subject entity. The runtime resolves the subject to the stored entity before writing.
Groups, Roles, and Permissions
Usegroup @id on an entity whose instances scope permissions, such as an Organization, Team, or Workspace.
Use role <fieldName> on the entity that carries role membership. The role field must be a non-optional enum. In the example above, Membership.membershipRole is the role field.
Permission statements start at a subject entity, traverse relation fields, and end at one role enum value:
permissions User->memberships->admin
That grants the listed permission strings to users whose memberships path resolves to a Membership with role admin.
Trigger Auth Rules
Triggerauth blocks support these predicates:
@subject is @definedfor any authenticated subject.@subject is @anonymousfor anonymous callers.@subject is adminfor a role by name.@subject is admin in Organization(@request.path.organizationId)for a role scoped to a group instance.@subject can "project:read"for a global permission.@subject can "project:read" in Organization(@request.path.organizationId)for a permission scoped to a group instance.
and and or. Parenthesized auth subexpressions are not supported by current validation, so write combined rules without parentheses. If a trigger omits auth, it is public.
Generated Auth Endpoints
When a SLang app defines a subject with an identity field, the generated app exposes standard auth endpoints for that subject model:POST /registerPOST /loginPOST /refreshGET /.well-known/jwks.json
identity and password. The identity value should match the field declared by identity <fieldName>, such as the user’s email address.