> For the complete documentation index, see [llms.txt](https://docs.sacruda.nl/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.sacruda.nl/developers/sacruda-apis/secure-context.md).

# Secure context

Also known as Elevation

You might have interacted with one already: Sacruda has a *Secure Context*, basically a glorified confirmation dialog that asks the user if they want to continue with any given operation. You can compare this to a `sudo` prompt in macOS or Linux, or the User Account Control dialog on Windows.&#x20;

There are two ways to elevate: either you call `UserDaemon.manuallyElevate` (manual elevation), or you call `AppProcess.elevate` (predefined elevation). Here's both methods expained in detail:

### Manual elevation

To manually elevate, call the `UserDaemon.manuallyElevate` method *in your process class*. Do it like this:

```javascript
const image = await fs.direct(util.join(workingDirectory, "icon.png"));
const elevated = await daemon?.elevation?.manuallyElevate({
   what: "Sacruda needs your permission to delete an application",
   image,
   title: "Minesweeper",
   description: "by Izaak Kuipers",
   level: 1, // 0-low, 1-medium, 2-high severity
});
```

Here I'm asking the user permission to delete the **Minesweeper** application, with a medium severity and an image URL I loaded using [direct file access](https://docs.sacruda.nl/developers/sacruda-apis/the-filesystem.md#direct-file-access). The asynchronous function returns a boolean that returns `true` if the user permitted the elevation request.

{% hint style="info" %}
The `manuallyElevate` method is asynchronous, it has to be awaited.
{% endhint %}

### Predefined elevation

A predefined elevation is saved in the `elevations` property of your app's process. For example, if you have an elevation that needs to be presented a bunch of times, you can save it in this property and elevate using an ID later. Here's how:

#### In your render method:

```javascript
async render() {
   // . . .
   this.elevations.deleteMinesweeper = {
    what: "Sacruda needs your permission to delete an application",
    image: await fs.direct(util.join(workingDirectory, "icon.png")),
    title: "Minesweeper",
    description: "by Izaak Kuipers",
    level: 1, // 0-low, 1-medium, 2-high severity
  }
  // . . .
}
```

And then anywhere else in your app process:

```javascript
const elevated = await this.elevate("deleteMinesweeper");
```

{% hint style="info" %}
The `elevate` method is asynchronous, it has to be awaited.
{% endhint %}

### When should you elevate?

You should elevate only when you're about to perform big operations that the user might regret. Basically, if you're about to delete an app, change a security setting, kill a process, you're expected to elevate. You don't have to elevate for deleting a note from a ToDo list, just use the `MessageBox` function for that. Learn more about [message boxes](https://docs.sacruda.nl/developers/sacruda-apis/message-boxes.md).
