Advanced

Auto Imports

Auto-imported utilities.

defuReplaceArray

The defuReplaceArray utility is provided to help you merge your security rules recursively.

It is a variant of the standard defu utility that replaces array contents instead of merging it.

Replacing array content

With defuReplaceArray, array content is merged with replacement:

const existingArray = ['a', 'b']
const newArray = ['c']
const result = defuReplaceArray(newArray, existingArray)
// ['c']

Compare with the standard defu approach, which merges arrays with addition:

const existingArray = ['a', 'b']
const newArray = ['c']
const result = defu(newArray, existingArray)
// ['a', 'b', 'c']

Server import

Nuxt Security auto-imports the defuReplaceArray function by way of a server import.

You can use it anywhere in your server routes, plugins, middlewares etc.

You cannot use this function outside of your /server folder.