National Commerce Docs
n8n flows

Invite Users to Client Portal

Invites one or more users to an account's client portal: creates the auth user, assigns the account role, and emails a welcome message telling them to sign in with a code.

Invites one or more users to the National Commerce client portal for a given account. It creates the Supabase auth user, assigns the account role, and emails a branded welcome message. It also handles the "already a member" case.

At a glance

  • Status: Active
  • Trigger: Webhook (POST /webhook/0805be40-1cc9-4415-8355-80bc16122185), answered by a Respond-to-Webhook node.
  • Runs on: A call carrying one or more users and their accounts, from the portal's invite route (server side) or New Brand Onboarding. The portal reads this webhook's URL from N8N_INVITE_WEBHOOK_URL, which is set on production only.
  • Talks to: Supabase (Auth Admin generate_link, get_user_uuid_by_email RPC, userRoles); Gmail.

How it works

  1. The webhook responds immediately, then Prepare Users Array feeds a counter loop over each user.
  2. Get User Via Email calls the Supabase RPC get_user_uuid_by_email, then branches on whether the user exists.
  3. Existing users: check userRoles for the account and either return a 400 "already exists" or add a new account role.
  4. New users: Generate Invite Link For User calls Supabase Admin generate_link with type invite. This is what creates the auth user. Then the welcome email is sent, and in parallel Build Account Roles makes one userRoles row per account for Add New User Role To Brand1 to insert.
  5. Send Invite Email sends a branded HTML message via Gmail. It tells the user to go to portal.nationalcommerce.com/login, enter their email, and sign in with the 6-digit code they're sent. There is no password to set.

The invite link is no longer used

generate_link still returns a one-time link (with redirect_to pointing at the old /update-password page, which no longer exists). The email does not include it. The step is kept because it is what creates the user.

Notes

  • Called by New Brand Onboarding.
  • callerPolicy: workflowsFromSameOwner.
  • Accounts: the body's brand_ids list, or brand_id alone for callers that send one account (New Brand Onboarding).
  • Type: new users are Client Users unless the call carries role_id for NC Internal User and the x-invite-secret header matching the shared secret in Build Account Roles. The portal sends it from the N8N_INVITE_SECRET env var, so the public webhook URL alone can't create an NC Internal User. NC Super Admin is never accepted.
  • The existing-user branch still adds a Client User row for the one brand_id. The portal only sends brand-new emails here; it gives existing users their accounts itself.
  • Shared error-handler set as the error workflow.
  • Create Default User Preferences, Add User Preferences, and Assign User To Brand sit on the canvas but nothing connects into them, so they never run. New users get no user_settings row from this flow, which is why every email starts off. See Notifications.
  • A new user who requests a sign-in code within a minute of the invite gets "Too many requests". generate_link marks the address as just emailed, and each address can get one email per minute.
  • The Supabase service key is hardcoded in the HTTP Request nodes' headers rather than stored as an n8n credential.

On this page