Skip to main content
GatoJS is built for agencies and teams that build an app, hand it over to a client, and keep supporting it for a while. Two global roles make that work:
  • superadmin is the service account of the team that builds and maintains the app. It keeps access for the support period, and the client can’t change or remove it.
  • admin is the client’s administrator. It manages users and data, but can’t touch service accounts.
See Superadmin and service mode for what each role can do inside the app. Because the client can’t remove service accounts, your team decides when support access ends, and removes it as described below.

At handover

Create the accounts right after the first successful deploy, before you open sign-up. On Railway, run admin:create from your machine through railway run with the database’s public URL (see Create the first accounts).
1

Create the service account with the client's organization name

The first admin:create on an empty database creates the organization, and --org-name only works then. Without it, the organization gets the placeholder project name.
2

Create the client admin

Omit --role; the default is admin.
Both accounts become owner of the same organization. The order of accounts doesn’t change that.
3

Let the client set their own password

Don’t hand over the generated password. Ask the client to use “forgot password” (/forgot-password) to set their own. It also proves that production email works.If you do share the generated password, use a secure channel and ask them to change it on /account. Neither a reset nor a change signs out other sessions, so don’t sign in to the client’s account yourself.
4

Walk through it with the client

The client signs in and opens Users. Service accounts show a service badge and no Sign in as button.
5

Agree on the flags

Decide with the client on ADMIN_IMPERSONATION (may their admin impersonate regular users?), MULTI_ORG and AUTH_PUBLIC_SIGNUP. Set them on the service and redeploy. Until now, AUTH_PUBLIC_SIGNUP must stay false.With AUTH_PUBLIC_SIGNUP=true and MULTI_ORG=false, anyone who signs up becomes a member of the client’s organization.
The badge text for service accounts comes from the role-superadmin key in src/features/users/i18n/en.json and pl.json. Change it to your team’s name.
A service account is an owner of the client’s organization, so it works there like any owner: no service-mode banner and no confirmation dialog on data changes. Service mode applies only when a superadmin works in an organization they’re not a member of.

Access outside the app

App roles don’t cover infrastructure. Anyone with access to the Railway project has the database and every variable, including BETTER_AUTH_SECRET. The kit doesn’t manage access to Railway, the repository, Resend or your log collector; agree on transferring those with the client separately.
When your team loses access to the hosting project, consider rotating BETTER_AUTH_SECRET. It signs session cookies, including the cookie cache that some code trusts without a database lookup, so anyone who knows it can forge a cookie. After rotation, every existing session stops working and everyone signs in again.

Remove support access

At the end of the support period, a superadmin removes the team’s access. The order matters because of how better-auth and the kit work:
  • An account can’t delete itself. /admin/remove-user answers 400 "You cannot remove yourself", so the last service account can’t remove itself.
  • Changing the role to user doesn’t remove the owner membership, so the account would still see organization data.
  • The change is one-way. Once the role is user, it can’t be restored: only a superadmin can grant superadmin.
  • Impersonation sessions outlive the impersonator. A Sign in as session belongs to the impersonated account, expires after 3600 seconds, and isn’t deleted when the service account is removed.
So your team removes every other service account, strips the last one of its role and memberships, and the client deletes what’s left. After step 6, your team has no access to app data. Deleting the account in step 7 cascades to its sessions, sign-in methods, memberships and the invitations it sent.

The API calls

The kit has no UI for changing roles, deleting accounts or leaving organizations, so these steps call better-auth endpoints under /api/auth/ from the browser’s developer console. Open the app at the APP_URL address and sign in first: fetch from that tab sends the session cookie and Origin header, and better-auth rejects other origins.
Hand the client a ready-made call for step 7 with the ID filled in, or run it together on a shared screen.

When you’re the only owner

If step 4 fails with "You cannot leave the organization as the only owner", the service account is the sole owner, for example of an organization it created itself with MULTI_ORG=true. This doesn’t happen in the organization created by admin:create, because the client admin is an owner too. The members form doesn’t assign owner, and better-auth lets only an owner grant it. So before step 5, while you’re still an owner, promote someone from the client who is a member:
  1. Open /api/auth/organization/list-members?organizationId=<organization id> and take the membership id (not userId) of that person.
  2. Run:
  3. Repeat step 4 for that organization.
If no one from the client belongs to it, for example a test organization of your own, delete it while you’re still owner: call /api/auth/organization/delete with { "organizationId": "<organization id>" }. With MULTI_ORG=false, the kit allows this only for a global admin or superadmin. Deleting cascades to its memberships and invitations.
Between steps 5 and 6, UI elements that read the role from the cookie cache may show admin menus for up to 5 minutes. Data stays protected: getOrgContext() reads the session from the database, bypassing the cookie cache.

Superadmin and service mode

What service accounts can do and how service mode works.

Auth and roles

Global roles, organization roles and sign-up policy.

Deploy on Railway

The deploy steps that come before handover.

Known limitations

Impersonation and service accounts after support.