Skip to content

Twig Auth Reference

The auth adapter provides authentication, user management, and fine-grained access control for templates.

Get a login URL. Supports collection-specific login and custom redirect URLs.

{# Default login with redirect back to current page #}
{{ cms.auth.login() }}
{# Collection-specific login #}
{{ cms.auth.login('members') }}
{# Login with no redirect #}
{{ cms.auth.login('', '') }}
{# Login with custom redirect #}
{{ cms.auth.login('', '/welcome') }}
{# Collection login with custom redirect #}
{{ cms.auth.login('members', '/dashboard') }}
ParameterTypeDefaultDescription
collectionstring''Collection to authenticate against
redirectstring|nullnullRedirect URL after login (null = current page, '' = no redirect)

Get a logout URL with optional redirect.

{{ cms.auth.logout() }}
{{ cms.auth.logout('/goodbye') }}
ParameterTypeDefaultDescription
redirectstring''Redirect URL after logout

Get the current logged-in user’s data as an array.

{% set user = cms.auth.userData() %}
{% if user %}
<p>Welcome, {{ user.name }}</p>
<p>Email: {{ user.email }}</p>
{% endif %}

Check if a user is currently logged in.

{% if cms.auth.userLoggedIn() %}
<a href="{{ cms.auth.logout() }}">Sign Out</a>
{% else %}
<a href="{{ cms.auth.login() }}">Sign In</a>
{% endif %}
{# Check login for specific collection #}
{% if cms.auth.userLoggedIn('members') %}
<p>Member area content</p>
{% endif %}
ParameterTypeDefaultDescription
collectionstring''Check login status for specific collection

Check if the current user is an admin. Admin users bypass all access controls.

{% if cms.auth.isAdmin() %}
<a href="{{ cms.dashboard }}">Admin Panel</a>
{% endif %}

Get a value from the session by key.

{{ cms.auth.sessionData('theme') }}
{{ cms.auth.sessionData('last_visited') }}

Returns: string|null — the session value or null if not found

Check if the current user belongs to one or more access groups.

{# Single group #}
{% if cms.auth.userHasAccess('editors') %}
<button>Edit Page</button>
{% endif %}
{# Multiple groups (user must match at least one) #}
{% if cms.auth.userHasAccess(['editors', 'admins']) %}
<div class="admin-tools">...</div>
{% endif %}
ParameterTypeDescription
groupsstring|arrayGroup name or array of group names
collectionstringOptional collection context (default: '')

Check if the current user can perform a CRUD operation on a specific collection.

{% if cms.auth.canAccessCollection('blog', 'read') %}
{# Show blog posts #}
{% endif %}
{% if cms.auth.canAccessCollection('products', 'create') %}
<a href="/products/new">Add Product</a>
{% endif %}
ParameterTypeDefaultDescription
collectionstringrequiredCollection identifier
operationstring'read'CRUD operation: read, create, update, delete

Get a list of collection IDs the current user can access with a given operation.

{% set readable = cms.auth.accessibleCollections('read') %}
{% for colId in readable %}
<p>{{ colId }}</p>
{% endfor %}

Check if the user can perform an operation on collections in general (not a specific collection).

{% if cms.auth.canAccessCollectionsOperation('create') %}
<a href="/collections/new">New Collection</a>
{% endif %}

Check if the user can perform an operation on a specific collection’s metadata.

{% if cms.auth.canAccessCollectionMeta('blog', 'update') %}
<a href="/admin/collections/blog/settings">Collection Settings</a>
{% endif %}

Check if the user can perform metadata operations on collections in general.

{% if cms.auth.canAccessCollectionsMetaOperation('read') %}
{# Show collection settings link #}
{% endif %}

Check if the user can perform a CRUD operation on a specific schema.

{% if cms.auth.canAccessSchema('blog', 'update') %}
<a href="/admin/schemas/blog">Edit Schema</a>
{% endif %}

Check if the user can perform operations on schemas in general.

{% if cms.auth.canAccessSchemasOperation('create') %}
<a href="/admin/schemas/new">New Schema</a>
{% endif %}

Check if the user can access templates.

{% if cms.auth.canAccessTemplates() %}
<a href="/admin/templates">Templates</a>
{% endif %}

Check if the user can access a specific utility page.

{% if cms.auth.canAccessUtil('jumpstart') %}
<a href="/admin/utils/jumpstart">JumpStart</a>
{% endif %}

Check if the user can access any utility pages.

{% if cms.auth.canAccessUtils() %}
<a href="/admin/utils">Utilities</a>
{% endif %}

Check if the user can access the mailer collection.

{% if cms.auth.canAccessMailer() %}
<a href="/admin/mailer">Mailer</a>
{% endif %}

Check if the user can access the playground.

{% if cms.auth.canAccessPlayground() %}
<a href="/admin/playground">Playground</a>
{% endif %}

Check if the user can access data views.

{% if cms.auth.canAccessDataViews() %}
<a href="/admin/dataviews">Data Views</a>
{% endif %}

Check if the user can access documentation.

{% if cms.auth.canAccessDocs() %}
<a href="/admin/docs">Documentation</a>
{% endif %}

Verify a password for accessing a protected file or depot item.

{% if cms.auth.verifyFilePassword(password, 'documents', docId, 'file') %}
<a href="{{ cms.media.download(docId, {pwd: password}) }}">Download</a>
{% else %}
<p>Invalid password</p>
{% endif %}
{# For depot files, include the filename #}
{% if cms.auth.verifyFilePassword(password, 'files', objId, 'depot', 'report.pdf') %}
<a href="{{ cms.media.depotDownload(objId, 'report.pdf', {pwd: password}) }}">Download Report</a>
{% endif %}
ParameterTypeDefaultDescription
passwordstringrequiredPassword to verify
collectionstringrequiredCollection identifier
idstringrequiredObject identifier
propertystringrequiredProperty name
namestring|nullnullFilename (for depot files)

Render the passkey management UI for registering and managing WebAuthn passkeys.

<div class="security-settings">
<h3>Passkeys</h3>
{{ cms.auth.passkeyManager()|raw }}
</div>