# Block a user

If you are the website owner, you can block users by adding their signing key to the appendable data associated with the current page.

#### Contents

![Block a user](/files/-M2iQeM8wC2B--vQrc5u)

## Get the signing key of a user

The plugin fetches the signing key of the user you want to block.

#### [Get signing key handle at index](https://api.safedev.org/low-level-api/appendable-data/get-signing-key-handle-at-index.html#for-a-data-item)

```
GET /appendable-data/sign-key/:handleId/:index
```

**controller.js**

```javascript
window.safeAppendableData.getSignKeyAt(this._authToken, this._currentPostHandleId, index)
```

## Add the signing key to the filter

The plugin adds the signing key of the user you want to block to the filter of the appendable data associated with the current page. Since the filter of the appendable data is a blacklist, everyone except the keys listed in the filter will be allowed to append data.

#### [Add signing keys](https://api.safedev.org/low-level-api/appendable-data/filter/add-signing-keys.html)

```
PUT /appendable-data/filter/:handleId
```

**controller.js**

```javascript
window.safeAppendableData.addToFilter(this._authToken, this._currentPostHandleId, [signKeyHandleId])
```

## Save the appendable data

The plugin updates the appendable data associated with the current page by sending a POST request to the SAFE Network.

#### [Save appendable data](https://api.safedev.org/low-level-api/appendable-data/save-appendable-data.html#post-endpoint)

```
POST /appendable-data/:handleId
```

**controller.js**

```javascript
window.safeAppendableData.post(this._authToken, this._currentPostHandleId)
```

Whenever you block a user, the plugin adds their public name and their signing key to a structured data associated with the current page. Using this list of blocked users, you can [unblock a user](/safe-dev-tutorials/website-with-comments/unblock-a-user.md) based on their public name.

**controller.js**

```javascript
this._saveBlockedUser(userName, signKeyHandleId)
```

## Serialize the signing key

The plugins serializes the signing key of the user you want to block.

#### [Serialize signing key](https://api.safedev.org/low-level-api/appendable-data/signing-key/serialize-signing-key.html)

```
GET /sign-key/serialise/:handleId
```

**controller.js**

```javascript
window.safeSignKey.serialise(this._authToken, signKeyHandle)
```

## If the structured data for blocked users is found

The plugin adds the serialized signing key of the user you want to block to the list of block users for the current page.

**controller.js**

```javascript
this._data.blockedUsers[userName] = serialisedSignKey
```

### Update the structured data

The plugin updates the structured data with the new list of block users.

#### [Update structured data](https://api.safedev.org/low-level-api/structured-data/update-structured-data.html)

```
PATCH /structured-data/:handleId
```

**controller.js**

```javascript
window.safeStructuredData.updateData(
    this._authToken,
    this._blockedUserStructureDataHandle,
    new Buffer(JSON.stringify(this._data.blockedUsers)).toString('base64'), this._symmetricCipherOptsHandle)
```

### Save existing structured data

The plugin saves the structured data by sending a POST request to the SAFE Network.

#### [Save structured data](https://api.safedev.org/low-level-api/structured-data/save-structured-data.html#post-endpoint)

```
POST /structured-data/:handleId
```

**controller.js**

```javascript
window.safeStructuredData.post(
    this._authToken,
    this._blockedUserStructureDataHandle)
```

After the user has been blocked, the plugin [reloads the comments](/safe-dev-tutorials/website-with-comments/fetch-comments.md).

## If the structured data for blocked users is not found

The plugin creates a new structured data based on the URL of the current page. This structured data will be used to store the list of blocked users for the current page. Whenever you want to block a user, the plugin will add their public name and their signing key to that structured data.

### Create a structured data

The plugin creates a new structured data that contains the public name and the serialized signing key of the user you want to block.

**controller.js**

```javascript
this._data.blockedUsers = {}
this._data.blockedUsers[userName] = serialisedSignKey
```

#### [Create structured data](https://api.safedev.org/low-level-api/structured-data/create-structured-data.html)

```
POST /structured-data
```

**controller.js**

```javascript
window.safeStructuredData.create(
    this._authToken,
    this._getLocation() + '_blocked_users', 500,
    new Buffer(JSON.stringify(this._data.blockedUsers)).toString('base64'),
    this._symmetricCipherOptsHandle)
```

### Save new structured data

The plugin saves this new structured data by sending a PUT request to the SAFE Network.

#### [Save structured data](https://api.safedev.org/low-level-api/structured-data/save-structured-data.html#put-endpoint)

```
PUT /structured-data/:handleId
```

**controller.js**

```javascript
window.safeStructuredData.put(
    this._authToken,
    this._blockedUserStructureDataHandle)
```

After the user has been blocked, the plugin [reloads the comments](/safe-dev-tutorials/website-with-comments/fetch-comments.md).

## Drop the handle for the signing key

The plugin drops the handle that represents the signing key of the user you just blocked.

#### [Drop signing key handle](https://api.safedev.org/low-level-api/appendable-data/signing-key/drop-signing-key-handle.html)

```
DELETE /sign-key/:handleId
```

**controller.js**

```javascript
window.safeSignKey.dropHandle(this._authToken, signKeyHandleId)
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://safenetwork.gitbook.io/safe-dev-tutorials/website-with-comments/block-a-user.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
