सामग्री पर जाएँ
ऑराबेस लोगो
aurabase

बहु-किरायेदार आरबीएसी

Aurabase प्रामाणिक के शीर्ष पर मॉडल एप्लिकेशन भूमिकाएँ (व्यवस्थापक, संपादक, दर्शक, बिलिंग)। फ़्लैट, पदानुक्रमित संगठनों और प्रति-संसाधन अनुमतियों के लिए पैटर्न।

कैसे-करें गाइड10 मि॰ पढ़ेंस्तर विकसित

इस अनुवाद के बाद से अंग्रेजी स्रोत बदल गया है। कुछ जानकारी पुरानी हो सकती है.
यह पृष्ठ स्वचालित रूप से अनुवादित किया गया था. अंग्रेजी संस्करण प्रामाणिक है.

Tables: members, roles, permissions#

create table orgs (id uuid primary key default gen_random_uuid(), name text not null);

create table org_members (
  org_id   uuid references orgs(id) on delete cascade,
  user_id  uuid not null,                     -- the user id (auth.uid()); users live in the auth service, not in a table you can reference
  roles    text[] not null default '{}',
  primary key (org_id, user_id)
);

Inject the roles into the JWT#

An Edge Function connected like Auth Hook enriches the JWT with tenant (active org_id) + roles (array). They are merged into the token's app_metadata, where auth.tenant() and auth.has_role() read them in your policies.

Deno.serve(async (req) => {
  // Request: { event, project_id, user_id, email, role }, signed with X-Hook-Signature.
  const { user_id } = await req.json()
  const { data: m } = await aura
    .from('org_members')
    .select('org_id, roles')
    .eq('user_id', user_id).single()

  // Response: { claims: { … } }. Its keys are merged into app_metadata. A hook that fails,
  // answers with anything else, or sets a protected claim (sub, role, aud…) refuses the sign-in.
  return Response.json({
    claims: { tenant: m?.org_id, roles: m?.roles || [] },
  })
})
जानकारी

The hook executes on sign-in and on each refresh. Modifying a user's roles becomes active at their next token refresh (max 15 min).

Combine tenant + roles#

-- Any member of the org sees the projects
create policy "projects_read" on projects
  for select to aura_authenticated
  using (org_id = auth.tenant());

-- Only admin can create/delete
create policy "projects_admin" on projects
  for all to aura_authenticated
  using (org_id = auth.tenant() and auth.has_role('admin'))
  with check (org_id = auth.tenant());

Automatic provisioning via SCIM#

On Enterprise plan, enable SCIM 2.0 from Okta, Azure AD, Google Workspace. Users + roles are synchronized automatically: immediate addition/removal, instant deprovisioning when an employee leaves.

To go further#