as #

Returns a new EmbeddedSDK instance impersonating the provided user.

Arguments #

as (user: { _id: string }, options = { checkRights: false }): EmbeddedSDK;

ArgumentTypeDescription
user
{ _id: string }
User object with at least the _id property
options
object
Optional object with the checkRights property (default: { checkRights: false })

options:

Available since 2.10.0
PropertyType (default)Description
checkRights
boolean

(false)
If true, will check if the impersonated user is allowed to execute any following actions

Returns #

Returns a new impersonated EmbeddedSDK instance.

Throws a plugin.context.invalid_user error if user is not an object with a string _id property.

The impersonated SDK sends its requests through the query method of the EmbeddedSDK: the same auth actions are refused.

Usage #

await app.sdk.as(request.context.user, { checkRights: true }).document.create(
  'nyc-open-data',
  'yellow-taxi',
  { name: 'Aschen' });