# Add teams to a Replit app (React and Express, BuildBase sign-in)

One prompt that adds a workspace switcher, members and email invites to a Replit Agent app, and scopes your own tables by workspace.

Replit can also connect to BuildBase itself while it builds: [Use BuildBase in Replit](/console/ai-agents/replit).

Each customer gets a workspace, a switcher in the header, and a members screen where an admin invites a colleague by email. Workspaces, members and roles live in BuildBase; your own tables stay in Replit Database, scoped by the workspace id. This page assumes the app already signs people in with @buildbase/sdk, as the [Replit guide](https://www.buildbase.app/guides/add-login-teams-and-paid-plans-to-a-replit-app) sets up. If it signs people in with something else, such as Supabase or Clerk, read [keep your existing sign-in](/sign-in-setup/keep-your-sign-in) first.

> **Note:**
  A sender connected in the console, so invitation emails go out ([connect a
  sender](/email/connect-a-sender)).

## The prompt

[Open in Replit](https://replit.com/?stack=Build&prompt=CoCwlgzgBAhgDnKEwHMB204FMD2cA2WUYaUA7mAC4hQBCArmPgCa0wREAUAAgEaMte7LAHoIzANYBKADRIslKPUTsoISpTgQAXCJFkDAOn5NmQjofhwRKRsywQRMZswC0+HChKvKWGAFsIVxg0NzgYMDD8EKDKHGDXACcsAipghCQQHDIIQygASQAzYkVmHAcoNBxKOQg4lVCoX3x8KH8sQwAoACU-ZjUNLV0RMoBjXJNBYUsEfRxEiQhw0YcRHAA3LET1sCwyQ39+wrBEuthGssrq4jRNtEUsULgcEkpcztcoAEEXKAB1eaLZZYADKFEooxAWyghUSOH8UD4AjMwjEkhEyRgo0UcSaULUfS2chC-RgUAAslh-LwttB+BocKRqDBFKMYC1oHhHgCFkssaCFJQSCgIJwAOT0DinMVSGFwhGS0EwGAgr70aicKRdT4AcTAmygWE2iQAnk0YLxCFAcMV-CQiGSyIC+SsAPqRKCjHD4ej+UgkmFMXyJQ3Gs0AR3oWzNvDNo3oiWS9x5QP5hndR3lSg4IOVIJTLocmu1BVIAFEAB5wZIQaBw9UOOSQrCjCR4ohO3nA4iZ+HtqDJSMORSQG5QXi8ABi804g61ndTK0M+EglE1cr7UuNIkmKIsb3HWEK8yImOYwutIbIiSoF6odey7wAIjgrqzMb5yM7gXJ2tTaeAiDzAO3pEJQFqENAJBQL0qSKE+LIWsIxIXK+VSKM4-SwSuihqtQl5QAAwoQCwANx0MibAcGo3rMNA1BUoYQA&referrer=docs.buildbase.app)

The link opens Replit Agent with the prompt filled in, for a new app; you still send it yourself. For the app you already have, paste the prompt into Agent's chat in that project instead.

```text
This app signs people in with BuildBase (@buildbase/sdk), set up as https://www.buildbase.app/guides/add-login-teams-and-paid-plans-to-a-replit-app shows. If it does not, stop and tell me.
Read https://docs.buildbase.app/workspaces/overview.md first and do not invent endpoints.
- Add WorkspaceSwitcher from @buildbase/sdk/react to the header, and a Members button that calls openWorkspaceSettings('users') from useSaaSAuth().
- Give every table of mine a workspace_id column and filter every query by currentWorkspace._id from useSaaSWorkspaces().
- In Express routes, check the workspace id from the request is in bbFor(req).workspace.list() from server/buildbase.ts before reading or writing its rows.
Do not create workspace, membership or role tables in Replit Database, and do not add Replit Auth or Clerk; BuildBase holds them.
```

## Where the secrets go

This job adds no new secret. `BUILDBASE_CLIENT_SECRET` stays where the guide put it: the Secrets tool (**Tools** > **Secrets**), and again under **Publishing** > **Adjust settings** > **Production app secrets**. Never give it a `VITE_` prefix. The routes use the signed-in person's session cookie, `bb-session-id`.

## The Replit trap

Replit Database is PostgreSQL that your Express server reads with a server-side connection, so there is no row rule to fall back on: the check lives in the route or nowhere. The bug to look for in every change Agent makes is a query that filters by the row id and not by `workspace_id`.

Test it: sign in as a member of one workspace and change an id in the address bar. If you see another workspace's rows, a query is missing its filter. Keep the guide's two lines in `replit.md`, which Agent reads before every request, so the habit outlives this prompt.

## Full guides

- [Add login, teams and paid plans to a Replit Agent app](https://www.buildbase.app/guides/add-login-teams-and-paid-plans-to-a-replit-app)
- [Workspaces](/workspaces/overview) and [invitations](/workspaces/invitations)
- [Add BuildBase to Replit as a skill](/ai-builders/replit-import)
