# JavaScript examples: logged-in user and app details

> Read the signed-in user, the app's ID, name and time zone, app variables and app secrets in a Run Custom Code step, with examples.

Source: https://tadabase.com/docs/workflows/logged-in-user-app-context-snippets  
Status: Verified Nov 17, 2026. Checked against the current product

In a **Run Custom Code** workflow action, four built-in helpers tell your code who started the run and which app it is in, and read the app's saved values. New to the action? Start with [Running Custom Javascript](https://tadabase.com/docs/workflows/running-custom-javascript).

## The helpers

| Helper | Returns |
| --- | --- |
| `getLoggedInUser()`, or `$loggedUser` | The signed-in user's record as an object, or `null` when no user is signed in. |
| `getAppDetails()` | An object with the app's `id` (encoded), `name` and `timezone`. |
| `getAppVariable("slug")` | The value of the [app variable](https://tadabase.com/docs/settings/app-variables) with that slug, or `undefined` if there is none. |
| `getAppSecret("NAME")` | The value of the [app secret](https://tadabase.com/docs/settings/app-secrets) with that name, or `undefined` if it is missing or inactive. |

- The helpers take no options. `getLoggedInUser()` and `getAppDetails()` always return the whole object, so read a property from it: `getLoggedInUser().email`. Older examples that pass a field name and a default, such as `getLoggedInUser("email", "")`, do not work that way.
- `getAppVariable` has no default argument. Write `getAppVariable("slug") ?? "fallback"` instead.
- Write the secret's name in quotes in `getAppSecret("NAME")`. Only secrets named that way are sent to the code, and their values are masked in the step's output.

## When there is no logged-in user

A user is available only when a signed-in app user started the run, for example by submitting a form or clicking a button. The run keeps that user even when it waits in the queue.

Runs with no logged-in user:

- Scheduled workflows.
- Workflows started by an incoming webhook or an incoming email.
- Changes made by someone who is not signed in to the app.

Always check for `null` before you read the user. In the code window, **Run** uses the user you pick with **Choose User** on the **Sample Data** tab.

## What is in the user object

The user object holds the user's record from the Users table: `email` and the values of the table's fields, keyed by field slug. To see the keys in your app, go to **Sample Data**, click **Choose User**, then type `$loggedUser.` in the code to get a list.

For one value, an input is often simpler. Click **+ Add Input** and pick **Logged-in User Field** to pass one field, or **Logged-in User (Full Object)** to pass the whole record. In the full-object input, `id` is the user's encoded record ID, the same form a Connection field to the Users table holds.

## Greeting with safe fallbacks

```js
// Input: userName (Logged-in User Field: the Name field)
const user = getLoggedInUser();
if (!user) {
  returnData("greeting", "Hi there!");
  return;
}

const name = String($userName || "").trim()
  || String(user.email || "").split("@")[0]
  || "there";

returnData("greeting", "Hi, " + name + "!");
```

`$userName` exists only if you added that input. Without it, use `user.email` alone.

## Stop when no one is signed in

```js
const user = getLoggedInUser();
if (!user) {
  fail("This step needs a signed-in user.");
}

returnData("user_email", user.email || "");
```

`fail` stops the step with your message in the run log. Turn on **Abort workflow if this step fails** if the later steps must not run either.

## Only the record's owner may act

```js
// Inputs:
//   me       (Logged-in User (Full Object))
//   ownerIds (Record Value (Source): a Connection field to Users, e.g. "Owner")
const myId = $me ? $me.id : null;
const owners = Array.isArray($ownerIds) ? $ownerIds : [];

returnData("is_owner", !!myId && owners.indexOf(myId) !== -1);
```

Both values are encoded record IDs, so they can be compared directly. Follow the step with a condition on `is_owner`.

> **Note:** For checks on the user's role, a condition in the workflow is usually simpler than code. See [Conditions and branches](https://tadabase.com/docs/workflows/conditions-and-branches).

## Read an app variable with a fallback

```js
const supportEmail = getAppVariable("support_email") ?? "support@example.com";
const appName = getAppDetails().name || "Our app";

returnData("footer", appName + ". Questions? " + supportEmail);
```

## Switch behavior with an app variable

```js
// App variable: new_checkout = "on" or "off"
const on = String(getAppVariable("new_checkout") ?? "off").toLowerCase() === "on";

returnData("flow", on ? "new" : "classic");
```

Change the variable's value in **Settings** to change the workflow's behavior without editing the code.

## Different settings for testing and live use

```js
// App variable: env = "staging" or "production"
const env = getAppVariable("env") ?? "production";

const apiBase = env === "production"
  ? "https://api.example.com"
  : "https://api.staging.example.com";

returnData("env", env);
returnData("api_base", apiBase);
```

## Link back into the app

`getAppDetails()` does not include the app's web address. Save it once as an app variable, for example `app_url`, and build links from it:

```js
// App variable: app_url, e.g. https://yourapp.tadabase.io
const base = String(getAppVariable("app_url") ?? "").replace(/\/+$/, "");
const link = base + "/jobs/details/" + ($record ? $record.id : "");

returnData("record_link", link);
```

Replace `/jobs/details/` with the path of the page that shows the record in your app.

## Who, where and when, for an outgoing call

```js
const user = getLoggedInUser();
const app = getAppDetails();

returnData("context", {
  user_email: user ? user.email || null : null,
  app_id: app.id,
  app_name: app.name,
  app_timezone: app.timezone,
  record_id: $record ? $record.id : null,
  sent_at: new Date().toISOString()
});
```

A later step, or a `fetch` call in the same code, can send this object to an audit log or CRM.
