Skip to content

User Data Management

Store and manage user-specific JSON data such as notes, carts, preferences, or any custom application data. All operations are scoped per user. With a publishable key the user comes from the session cookie and any userId you pass is ignored (401 NO_USER_SESSION if nobody is signed in); a secret key may act on any user by id.

searchInUserData

POST /users/:userId/data/search

ParamTypeRequiredDescription
userIdstringYesUser ID
categorystringNoFilter by category
qstringNoSearch text query
keysobjectNoKey-value filtering object
TypeScript
1const res = await authix.searchInUserData({
2  userId: "user123",
3  category: "notes",
4  q: "important",       // substring match across the record
5  keys: { status: "open" },  // exact field match
6  limit: 20,
7});
8
9console.log(res.data, res.hasMore, res.nextCursor);

getUserData

GET /users/:userId/data

ParamTypeRequiredDescription
userIdstringYesUser ID
limitnumberNoPagination limit (default 20)
cursorstringNoPagination cursor
categorystringNoFilter by category
TypeScript
1const res = await authix.getUserData({
2  userId: "user123",
3  limit: 20,
4  category: "notes",
5  cursor: undefined,
6});
7
8console.log(res.data, res.hasMore, res.nextCursor);

getSingleUserData

GET /users/:userId/data/:dataId

ParamTypeRequiredDescription
userIdstringYesUser ID
dataIdstringYesData item ID
TypeScript
1const item = await authix.getSingleUserData({
2  userId: "user123",
3  dataId: "note_1",
4});

Create, Update & Delete

addUserData

POST /users/:userId/data

ParamTypeRequiredDescription
userIdstringYesUser ID
dataCategorystringYesCategory name
dataobjectYesData object
TypeScript
1const res = await authix.addUserData({
2  userId: "user123",
3  dataCategory: "notes",
4  data: {
5    title: "My Note",
6    content: "Hello world",
7  },
8});

updateUserData

PUT /users/:userId/data/:dataId

TypeScript
1await authix.updateUserData({
2  userId: "user123",
3  dataId: "note_1",
4  data: {
5    title: "Updated title",
6  },
7});
8
9// Pass the version you last read for optimistic concurrency.
10// If someone else changed the record meanwhile, this throws
11// instead of silently overwriting their change.
12try {
13  await authix.updateUserData({
14    userId: "user123",
15    dataId: "note_1",
16    version: note.version,
17    data: { title: "Updated title" },
18  });
19} catch (err) {
20  if (err.isConflict) {
21    // Re-read and retry — err.currentVersion tells you what it is now.
22  }
23}

deleteUserData

DELETE /users/:userId/data/:dataId

TypeScript
1await authix.deleteUserData({
2  userId: "user123",
3  dataId: "note_1",
4});
5
6// Or remove several at once, in a single transaction:
7await authix.deleteManyUserData({
8  userId: "user123",
9  dataIds: ["note_1", "note_2", "note_3"],
10});

batch

POST /users/:userId/data-batch

TypeScript
1// Every operation commits, or none do.
2// Use this when two records must change together.
3
4await authix.batch({
5  userId: "user123",
6  operations: [
7    { type: "create", dataCategory: "orders", total: 40, status: "paid" },
8    { type: "update", id: stockId, version: 3, remaining: 9 },
9    { type: "delete", id: draftId },
10  ],
11});
12
13// A version mismatch or a missing record aborts the whole batch
14// and nothing is written. Up to 50 operations per call.

Share links

Let a user share one record, such as a note, with anyone. The owner gets a token and puts it in your own URL. Whoever opens the link reads that record with your publishable key, without signing in. They never see the owner, other records or child records.

shareUserData / unshareUserData

POST /users/:userId/data/:dataId/share · DELETE /users/:userId/data/:dataId/share

ParamTypeRequiredDescription
userIdstringYesThe owner (taken from the session with a publishable key)
dataIdstringYesThe record to share
expiresInDaysnumber | nullNo1–3650 days, or null for no expiry. Omit to keep the current expiry
rotatebooleanNoIssue a new token; the old link stops working
TypeScript
1// Owner (signed in): turn on a link for one note
2const { data } = await authix.shareUserData({
3  userId: user.id,
4  dataId: note.id,
5  // expiresInDays: 7,  // optional; omit for a link that never expires
6});
7
8const link = `${location.origin}/s/${data.shareToken}`;
9
10// Same call again → same token (links already sent keep working).
11// rotate: true → new token, and the old link stops working.
12await authix.shareUserData({ userId: user.id, dataId: note.id, rotate: true });
13
14// Revoke it
15await authix.unshareUserData({ userId: user.id, dataId: note.id });

getSharedData

GET /shared/:token

ParamTypeRequiredDescription
tokenstringYesThe shareToken from shareUserData, read from your share URL
TypeScript
1// Viewer page, e.g. /s/[token] — nobody needs to sign in
2const authix = new NeuctraAuthix({
3  baseUrl: "https://server.authix.neuctra.com/api",
4  apiKey: process.env.NEXT_PUBLIC_AUTHIX_PUBLISHABLE_KEY, // pk_live_…
5  appId: process.env.NEXT_PUBLIC_AUTHIX_APP_ID,
6});
7
8try {
9  const { data: note } = await authix.getSharedData({ token });
10  render(note.title, note.content);
11} catch (err) {
12  // 404 SHARE_NOT_FOUND: revoked, expired or unknown link
13  showLinkUnavailable();
14}

Anyone with the link can read the record

Treat the token like a password for that one record. Your app's allowed origins still apply when the link is opened in a browser. Revoked, expired and unknown links all return the same 404, so a failed request never reveals whether a record exists. A field like public: true in your data shares nothing; only shareUserData does.

Pagination

Reads are always bounded

Every list and search endpoint returns at most limit records — 20 by default, 100 maximum. There is no way to request an unbounded result set, because a single such request on a large app would have to load the entire dataset into memory. Use nextCursor to page through the rest.

TypeScript
1// Results are always paginated — limit defaults to 20 and is
2// capped at 100. Follow nextCursor to read the rest.
3
4let cursor;
5do {
6  const page = await authix.getUserData({ userId: "user123", limit: 50, cursor });
7  page.data.forEach(handleRecord);
8  cursor = page.nextCursor;
9} while (cursor);
10
11// Or let the SDK walk the pages for you:
12for await (const page of authix.iterateUserData({ userId: "user123" })) {
13  page.data.forEach(handleRecord);
14}

Best Practices

  • Use consistent dataCategory values for filtering.
  • Do not store sensitive data like passwords or tokens.
  • Use pagination for large datasets.
  • Keep data structure consistent inside each category.
  • Wrap all SDK calls in try/catch for error handling.

Related docs