# Organizations for your users
Source: https://sovaria.in/docs/app-organizations

B2B apps: your users create organizations, invite teammates, give them roles and auto-join by verified email domain; the active organization is in every token for your policies.

When your customers are companies, their people need a shared workspace. `sovaria.auth.organizations` gives your app users organizations with members, roles (`owner`, `admin`, `member` or any role name of yours), email invitations and verified domains, without building it yourself.

JavaScript:
```js
const acme = await sovaria.auth.organizations.create('Acme Inc')          // you are its owner
await sovaria.auth.organizations.invite(acme.id, 'bob@acme.com', 'admin')  // emailed link, 7 days
await sovaria.auth.organizations.acceptInvite(tokenFromLink)              // by the invited, verified address

await sovaria.auth.organizations.setActive(acme.id)   // the next tokens carry app_org
const { organizations } = await sovaria.auth.organizations.list()

await sovaria.auth.organizations.addDomain(acme.id, 'acme.com')           // publish the TXT record, then:
await sovaria.auth.organizations.verifyDomain(acme.id, 'acme.com')        // users with a verified @acme.com email join as members
```

## Use the organization in your rules

The active organization is in the token as `app_org` = `{ id, slug, role }`. Store an `org_id` on your rows and compare:

SQL:
```sql
create policy "members read their org's invoices" on invoices
  for select to authenticated
  using (org_id = (auth.jwt() -> 'app_org' ->> 'id')::uuid);
```

Guard:
```text
ALLOW IF ctx.resource.name == "invoices" AND ctx.action == "DELETE" AND ctx.org.role IN ["owner", "admin"]
```

- An organization always keeps an owner: the last one can't leave or be demoted. Only owners delete it, verify domains or invite another owner.
- A verified domain belongs to one organization per project; shared mailbox domains are refused.
- Your team sees every organization (and can delete one) under Authentication › Organizations.

## Plans

|  | Free | Pro | Ultra | Team | Enterprise |
|---|---|---|---|---|---|
| Tenant organizations | 1 | 10 | 100 | 2,000 | 10,000 |
