Extensions

Press shift + S to search API reference.

Model

Model class representing the current user's session.

import {useSession} from '@airtable/blocks/ui';
function Username() {
const session = useSession();
if (session.currentUser !== null) {
return <span>The current user's name is {session.currentUser.name}</span>;
} else {
return <span>This extension is being viewed in a public share</span>;
}
}

Members

class Session extends AbstractModel<SessionData, WatchableSessionKey>
readonly currentUserCollaboratorData | null

The current user, or null if the extension is running in a publicly shared base.

import {useSession} from '@airtable/blocks/ui';
function CurrentUser() {
const session = useSession();
if (!session.currentUser) {
return <div>This extension is being used in a public share.</div>;
}
return <ul>
<li>ID: {session.currentUser.id}</li>
<li>E-mail: {session.currentUser.email}</li>
<li>Name: {session.currentUser.name}</li>
</ul>;
}
readonly idstring

The ID for this model.

readonly isDeletedboolean

true if the model has been deleted, and false otherwise.

In general, it's best to avoid keeping a reference to an object past the current event loop, since it may be deleted and trying to access any data of a deleted object (other than its ID) will throw. But if you keep a reference, you can use isDeleted to check that it's safe to access the model's data.

checkPermissionsForCreateRecords
function () => PermissionCheckResult

Checks whether the current user has permission to create any records in the current base. For more granular permission checks, see Table.checkPermissionsForCreateRecords.

Returns {hasPermission: true} if the current user can create records, {hasPermission: false, reasonDisplayString: string} otherwise. reasonDisplayString may be used to display an error message to the user.

import {useSession} from '@airtable/blocks/ui';
function CreateButton({onClick}) {
const session = useSession();
const updateRecordsCheckResult = session.checkPermissionsForCreateRecords();
const deniedReason = updateRecordsCheckResult.hasPermission
? <span>{updateRecordsCheckResult.reasonDisplayString}</span>
: null;
return <div>
{deniedReason}
<button onClick={onClick} disabled={!!deniedReason}>
Create
</button>
</div>;
}
checkPermissionsForDeleteRecords
function () => PermissionCheckResult

Checks whether the current user has permission to delete any records in the current base. For more granular permission checks, see Table.checkPermissionsForDeleteRecords.

Returns {hasPermission: true} if the current user can delete records, {hasPermission: false, reasonDisplayString: string} otherwise. reasonDisplayString may be used to display an error message to the user.

import {useSession} from '@airtable/blocks/ui';
function DeleteButton({onClick}) {
const session = useSession();
const updateRecordsCheckResult = session.checkPermissionsForDeleteRecords();
const deniedReason = updateRecordsCheckResult.hasPermission
? <span>{updateRecordsCheckResult.reasonDisplayString}</span>
: null;
return <div>
{deniedReason}
<button onClick={onClick} disabled={!!deniedReason}>
Delete
</button>
</div>;
checkPermissionsForUpdateRecords
function () => PermissionCheckResult

Checks whether the current user has permission to update any records in the current base. For more granular permission checks, see Table.checkPermissionsForUpdateRecords.

Returns {hasPermission: true} if the current user can update records, {hasPermission: false, reasonDisplayString: string} otherwise. reasonDisplayString may be used to display an error message to the user.

import {useSession} from '@airtable/blocks/ui';
function UpdateButton({onClick}) {
const session = useSession();
const updateRecordsCheckResult = session.checkPermissionsForUpdateRecords();
const deniedReason = updateRecordsCheckResult.hasPermission
? <span>{updateRecordsCheckResult.reasonDisplayString}</span>
: null;
return <div>
{deniedReason}
<button onClick={onClick} disabled={!!deniedReason}>
Update
</button>
</div>;
}
hasPermissionToCreateRecords
function () => boolean

An alias for session.checkPermissionsForCreateRecords().hasPermission. For more granular permission checks, see Table.hasPermissionToCreateRecords.

hasPermissionToDeleteRecords
function () => boolean

An alias for session.checkPermissionsForDeleteRecords().hasPermission. For more granular permission checks, see Table.hasPermissionToDeleteRecords.

hasPermissionToUpdateRecords
function () => boolean

An alias for session.checkPermissionsForUpdateRecords().hasPermission. For more granular permission checks, see Table.hasPermissionToUpdateRecords.

toString
function () => string

A string representation of the model for use in debugging.

unwatch
function (keys: WatchableSessionKey | ReadonlyArray<WatchableSessionKey>, callback: function (model: this, key: WatchableSessionKey, args: ...Array<any>) => unknown, context?: FlowAnyObject | null) => Array<WatchableSessionKey>
keys

the keys to unwatch

callback

the function passed to .watch for these keys

context

the context that was passed to .watch for this callback

Unwatch keys watched with .watch.

Should be called with the same arguments given to .watch.

Returns the array of keys that were unwatched.

watch
function (keys: WatchableSessionKey | ReadonlyArray<WatchableSessionKey>, callback: function (model: this, key: WatchableSessionKey, args: ...Array<any>) => unknown, context?: FlowAnyObject | null) => Array<WatchableSessionKey>
keys

the keys to watch

callback

a function to call when those keys change

context

an optional context for this in callback.

Get notified of changes to the model.

Every call to .watch should have a matching call to .unwatch.

Returns the array of keys that were watched.