AuthJet
← Docs

Manage users and roles

You decide what people can do in your product. Your customers' admins decide who on their team can do it — without a ticket to you, and without you building a user-management backend.

How it fits together

Each customer company is an environment (tenant) in your account.

Defined byApplies toCan change it
PermissionsYouOne catalog for your whole productOnly you
Admin roleAuthJet (built in)Every environmentNobody
Standard rolesYouEvery environmentOnly you
Custom rolesA customer's AdminsThat one environmentIts Admins (and you)

Set it up (once)

  1. In the dashboard, open App Roles & Permissions and add your permissions, e.g. bookings:read.
  2. Add standard roles your product offers everyone, e.g. Staff and Manager.
  3. Optional: in Settings → Invite emails, set your own invite page (https://yourapp.com/join?token={token}). Leave it blank to use our hosted page.
  4. For each new customer, create their environment and invite their first person as Admin. From there, they run their own team.

What your customers' Admins can do

Can

  • See their company's users
  • Add people — email invite, or set a password so they can sign in straight away
  • Change roles (including making someone else an Admin), deactivate, reactivate and remove users
  • Create custom roles from any permission available to them

Can't

  • Create permissions or edit your standard roles
  • Change their own role or status, or remove themselves
  • Leave their company without an active Admin
  • Choose where invite emails link to — that’s your invite link setting

Seat limits apply to their invites. Everyone else in the company can only see their own profile.

Build a "Team" page in your app

With the JavaScript SDK, your frontend calls these endpoints directly with the signed-in Admin's token — no backend of your own needed.

TeamPage.tsx
import { useEffect, useState } from 'react'
import { useAuthFetch } from '@authjet/react'

const API = 'https://api.authjet.dev/api/v1'

type Member = { id: string; email: string; app_role: string | null; status: string }
type Role = { id: string; name: string; kind: 'admin' | 'standard' | 'custom' }

// A company Admin's "Team" page. Only users with the built-in Admin role get tenant_admin: true;
// everyone else gets 403 from these endpoints, so hide the page for them.
export function TeamPage() {
  const authFetch = useAuthFetch()
  const [isAdmin, setIsAdmin] = useState(false)
  const [members, setMembers] = useState<Member[]>([])
  const [roles, setRoles] = useState<Role[]>([])
  const [email, setEmail] = useState('')

  async function load() {
    setMembers((await (await authFetch(`${API}/users`)).json()).items)
    setRoles(await (await authFetch(`${API}/app-roles`)).json())
  }

  useEffect(() => {
    authFetch(`${API}/users/me`)
      .then((res) => res.json())
      .then((me) => {
        setIsAdmin(me.tenant_admin)
        if (me.tenant_admin) load()
      })
  }, [authFetch])

  async function invite(roleId: string) {
    // The email links to the invite page you set in AuthJet; they choose their own password.
    await authFetch(`${API}/users/invite`, {
      method: 'POST',
      headers: { 'Content-Type': 'application/json' },
      body: JSON.stringify({ email, app_role_id: roleId }),
    })
    setEmail('')
    await load()
  }

  async function changeRole(userId: string, roleId: string) {
    await authFetch(`${API}/users/${userId}`, {
      method: 'PATCH',
      headers: { 'Content-Type': 'application/json' },
      body: JSON.stringify({ app_role_id: roleId }),
    })
    await load()
  }

  if (!isAdmin) return null

  return (
    <div>
      <input value={email} onChange={(e) => setEmail(e.target.value)} placeholder="teammate@company.com" />
      {roles.map((r) => (
        <button key={r.id} onClick={() => invite(r.id)}>Invite as {r.name}</button>
      ))}
      <ul>
        {members.map((m) => (
          <li key={m.id}>
            {m.email} ({m.status})
            <select value={roles.find((r) => r.name === m.app_role)?.id ?? ''} onChange={(e) => changeRole(m.id, e.target.value)}>
              {roles.map((r) => (
                <option key={r.id} value={r.id}>{r.name}</option>
              ))}
            </select>
          </li>
        ))}
      </ul>
    </div>
  )
}

Endpoints (Admin only)

GET/api/v1/usersList users
POST/api/v1/users/inviteInvite by email (optional app_role_id)
POST/api/v1/usersCreate with a password (optional app_role_id)
PATCH/api/v1/users/{id}Change role (app_role_id), status or name
POST/api/v1/users/{id}/reactivateReactivate
DELETE/api/v1/users/{id}Remove
GET/api/v1/app-rolesRoles usable in this environment
POST · PATCH · DELETE/api/v1/app-rolesManage custom roles

Good to know