@softr/sdk
Version:
The SDK for building Softr apps on TanStack Start. It lets an app interact with Softr: auth, datasources, workflows and integrations.
22 lines (20 loc) • 902 B
JavaScript
import { makeChain } from "../datasource/fields.js";
import { listRecords } from "../datasource/record.js";
import "@tanstack/react-start/server-only";
//#region src/auth/current-user-row.ts
/**
* The signed-in visitor's own row of the Users table, found by email, or null when they are signed out
* or the table holds no row for them. For a "mine" filter, an owner set on create, or a page scoped to
* what the visitor owns: the row's id is what a link to Users holds.
*
* @example
* const me = await auth.currentUserRow(context.user, usersQuery, 'email')
* if (me === null) return []
* return ds.list(tasks).where((q) => q.assignee.isOneOf([me.id]))
*/
async function currentUserRow(user, usersQuery, email) {
if (user === null) return null;
return (await listRecords(usersQuery).where(() => makeChain(email).is(user.email)).limit(1)).records[0] ?? null;
}
//#endregion
export { currentUserRow };