Building User Authentication

By the end your app has a public landing page, a member area that sends visitors to sign in, an admin section only some accounts can open, and data filtered to whoever is calling. You wire your pages to the cluster's sign-in; you do not build one.

The cluster already handles accounts, sign-in and sessions

A scope decides who gets in

Every page, action and API gets its audience from a scope, set through the block's lock icon. Full mechanics are in Remote Access Control.

ScopeWho passesUse for
*publicAnyone, no tokenLanding pages, status endpoints, public content
*loggedinAny valid access_tokenMember areas, app pages, private APIs
Custom scope (e.g. billing_read)Users you granted that scopeRole-gated sections (admin, finance, support)

Grant custom scopes on the user's detail page (custom_scopes) or bundle them in user groups. See User Roles Explained.

No scope is not the same as public A web_page with no scope at all opens for developers only, and an API block with no scope answers every caller with a 403. Give each one a scope on purpose.

Three pages, three scopes

  1. A public landing page

    web_page (new web page) with event welcome and scope *public, flowing into web_render (web render). Use web.signed_in to show the right links.

    Template: welcome
    <header>
      <a href="/welcome">Home</a>
      {{if web.signed_in}}
        <a href="/account">Account</a>
        <a href="/security">Sessions and security</a>
      {{else}}
        <a href="/login?redirect=/account">Sign in</a>
      {{/if}}
    </header>
    <main>
      <h1>{{title}}</h1>
    </main>
  2. A member page

    web_page with event account and scope *loggedin. A visitor without a token is redirected to /login?redirect=/account and comes back after signing in. Feed user_current (current user) through user_convert_to_object (cast to object) into a custom pin me on web_render.

    Template: account
    <main>
      <h1>Hello {{me.username}}</h1>
      <p>Signed in as {{me.email}}.</p>
    </main>
  3. An admin page

    web_page with event admin and a custom scope such as billing_read. A signed-in user without that scope reads that they have no access. Keep it in its own blueprint, or set scopes on each web_action (on web action): an action without scopes of its own requires what every page of its blueprint requires.

How you know it worked: open all three in a private window. welcome shows, account sends you to the login page, and after signing in without the custom scope admin refuses you.

Sign-in happens on the cluster's login page

  1. The visitor is sent to sign in

    A page scoped *loggedin without a token redirects to /login.

  2. They sign in

    Password, plus a 2FA code when enabled. The cluster issues an access_token and sends them back.

  3. The token travels with each request

    As a cookie in the browser, or as a header or query parameter from your own frontend.

  4. Sign-out ends it at once

    Sign-out invalidates the token immediately. Users manage their sessions on the default security page.

Want your own look or passwordless codes? Building a Login Page replaces /login with a web page. Want Apple, Google or passkeys? See Single Sign-On. Building a separate frontend? Call POST /api/v1/auth/login with username and password and store the token; an account with 2FA gets an unverified token and must finish the challenge first. See the API workflows.

user_current tells a flow who is calling

Inside any authenticated flow, user_current (current user) gives you the calling user's document: guid, name, scopes.

To do thisWire this
Show people only their own datauser_current into user_get_guid (get guid), into a query_bool_term_fields (fields) on owner_guid. This is the denormalized owner pattern from Storages.
Show something to admins onlyuser_check_scope (has scope) into a custom pin is_admin on web_render, then {{if is_admin}} in the template.
Keep an audit trailWrite the actor's guid onto every document you create.

Gate the action

Set the scope on the web_action, or check user_check_scope in its flow, so the request itself is refused.

Only hide the button

A hidden button is not a gate. Anyone allowed on the page can still post to the action.

Check these before launch

  • Enable 2FA for everyone who can reach Studio or admin scopes.
  • Keep *public for content that truly is public. Check every page, action and API block once before launch.
  • Prefer custom scopes over checking usernames in flows.
  • Review the failed-login blocking and rate limits in Remote Access Control.
  • Audit access regularly on the User Activity page. See Auditing User Access.
  • Locked yourself out with a custom login page? Recover with ?studio=request. See Overwrite Default Pages.

Next steps

Building a Login Page Replace the default login with your own passwordless page. Single Sign-On Sign in with an account people already have. Getting Access Accounts, first login, cluster URLs, and API tokens. Remote Access Control Scopes, rate limits, and throttling in depth. User Roles Explained Permissions, scopes, and user groups by role.

Frequently asked

Do I need to build a login system in RUAL?

No. Every cluster already has accounts, sign-in, sessions and token management built in, including default login, password reset and security pages. Your job is to wire your app's pages and APIs to that system through scopes, not to build one.

How do I restrict a RUAL page to logged-in users?

Set the *loggedin scope on the page block through its lock icon. Unauthenticated visitors are then served the login page automatically, and after sign-in the cluster issues an access token and redirects them back.

How do I know which user is calling my RUAL flow?

The user_current block gives you the calling user's document with its guid, name and scopes. Use it to filter data to the caller in your queries, to branch on scope, or to write the actor onto every document you create.

How long does a RUAL access token stay valid?

14 days, extended automatically while actively used. Sign-out invalidates the token immediately, and users manage their sessions on the default security page.