Two User IDs: Account ID vs. Role Record ID

Every Knack user who signs in has two IDs, an Account ID and a role record ID. Learn which one Knack uses for ownership and which one connections use, so your custom frontend links records to the right person.

What You'll Learn

Every person who signs in to a Knack app has two different IDs: an Account ID and a role record ID. This article explains what each one is, which one Knack uses where, and how to make sure your frontend builder uses the right one, so records end up connected to and owned by the right person.

Every User Has Two Records

When someone has a login in your Knack app, they have a record in two places.

  • The Accounts table. Every user who signs in has one record here. Its ID is the Account ID. It answers "which person is this?"
  • Their user role table. A user with the Staff role also has a record in the Staff table, connected back to their Accounts record. Its ID is the role record ID.

They're the same person, but the two IDs are different, and they live in different tables.

Which ID Knack Uses Where

Where it's usedWhich ID
Who your app says is signed inAccount ID
Owned By, Created By, and Updated ByAccount ID
A connection field that points to a user role table, like an Appointment connected to a PatientRole record ID

So a record can be owned by a person's Account ID and connected to the same person's role record ID at the same time. Both are correct.

Why Mixing Them Up Breaks Things

A frontend builder knows who's signed in by their Account ID. If it uses that ID everywhere, connections break.

  • Connections come out empty or wrong. An Appointment connected to a Patient needs the patient's role record ID. The Account ID doesn't match any record in the Patients table.
  • Screens show nothing. A screen that finds "my appointments" by matching the Account ID against the Patient connection finds no matches.
  • Ownership comes out wrong. Owned By needs the Account ID. A role record ID won't match an account.

These problems don't always show an error. The record saves, but it isn't linked to the right person.

How to Find the Role Record ID

Your app gets the Account ID from the signed-in user's session. To get the role record ID, it looks up the person's record in their role table using the connection back to Accounts.

You don't need to do this yourself. Tell your frontend builder which ID to use where.

Tell Your Frontend Builder Which ID to Use

Add this to your frontend builder's standing instructions, like Lovable's Knowledge, or include it in your prompt.

Knack users have two IDs. Always use the right one:

- Account ID: the signed-in user's ID from the Knack session. Use it for Owned By, and for anything that asks who is signed in.
- Role record ID: the user's record in their user role table (for example, Staff or Patients). Use it for any connection field that points to a user role table.

To get the role record ID, look up the user's record in their role table using its connection to Accounts.

Never use the Account ID in a connection field that points to a user role table.

Check That Records Connect to the Right Person

After your frontend builder sets this up, test it.

  1. Sign in to your published app as a test user with one role
  2. Create a record that connects to that user, like an appointment or a note
  3. Open the record in the Knack Builder and check the connection field shows the right person
  4. Check that Owned By shows the same person
  5. Go back to your app and confirm the record appears on that user's screens

If the connection is empty but Owned By is right, the app is likely using the Account ID in the connection field.

Common Mistakes

  • Using the Account ID in a connection field. Connections to user role tables need the role record ID.
  • Using the role record ID for Owned By. Owned By uses the Account ID.
  • Assuming a saved record is a connected record. Check the connection field in the Knack Builder, not just that the record exists.
  • Matching screens on the wrong ID. "My records" screens need to compare the same kind of ID on both sides.
📘

For developers

The session endpoint returns the Account ID as session.user.id and the user's roles as profile_keys. To resolve the role record ID, query the role table filtered on its connection field to Accounts. See Runtime Data API.

Next Steps


Did this page help you?