Skip to content

Script Editor

The Script Editor lets you create and run custom scripts for tasks such as batch edits, user management, or automation. It has full TypeScript support and includes custom helpers that make scripting more convenient.

To open the Script Editor, select it from the workspace selector in the top-left corner.

The Script Editor shows a minimal async wrapper by default. This enables the use of await, which is convenient for working with the Firestore and Auth SDK but also required for helpers like pause and switchProject to work. If you prefer, you can also remove the wrapper and use .then() instead.

;(async () => {
// Your code goes here
})()

To execute a script, either click the Execute button in the bottom bar or press CMD/CTRL + Enter.

The Script Editor provides the Admin SDKs for Firestore and Auth.

You can use db just like in a Cloud Function to read and write data, run batch operations, and more:

;(async () => {
const snapshot = await db.doc('users/tNGb4hzbClMIcQs3aqcI').get()
console.log(snapshot.data())
})()

The auth function exposes the Authentication SDK to manage users:

;(async () => {
const { users } = await auth.listUsers()
console.log(`Found ${users.length} users`)
})()

Use console.log() to print messages to the output panel. While it supports objects, arrays, and other values, the output panel is more limited than your browser’s developer console. Use it as a simple way to inspect data, rather than a full-featured debugging environment.

By default, scripts run with the currently selected project. To switch projects mid-script — for example, to read data from one project and write it into another — use the switchProject() helper.

;(async () => {
await switchProject({
id: 'fire-corp',
emulator: false,
databaseId: 'staging',
})
const snapshot = await db.doc('config/rules').get()
await switchProject({
id: 'fire-corp',
emulator: true
})
await db.doc('config/rules').set(snapshot.data())
})()

You can also call switchProject() at the start of a script to ensure it always runs with the intended project, such as for project-specific maintenance scripts.

Use the pause() helper to temporarily stop a script. When execution reaches that line, the script pauses and a Resume and Cancel button appear in the bottom panel. The Resume button (or pressing CMD/CTRL + Enter) continues the script from the same point while Cancel stops the script entirely.

;(async () => {
const snapshot = await db.collection('oldUsers').get()
console.log(`Deleting ${snapshot.size} old users. Continue?`)
await pause() // check the count before continuing
for (const doc of snapshot.docs) {
await doc.ref.delete()
}
console.log('Delete complete.')
})()

This makes it easy to inspect intermediate results before continuing.

You can save scripts locally with Save (CMD/CTRL + S) or Save As (CMD/CTRL + Shift + S). Once a file has been saved, subsequent saves will overwrite it. Firelize shows a ● indicator next to the filename (similar to VS Code) whenever there are unsaved changes, so you can easily keep track of edits.

To open a previously saved script, click Open or press CMD/CTRL + O.

The Format button reformats your script using the built-in Prettier formatter. This ensures consistent indentation and styling throughout your code, and is especially useful when pasting snippets from different sources or after making quick inline edits.

The Wrap option toggles line wrapping, either breaking long lines to fit within the editor window or keeping them on a single scrollable line.