Allow to specify ADMIN_TOKEN in ENV (#22059) (#22724)

* Allow to specify ADMIN_TOKEN in ENV (#22059)

* Add changeset

---------

Co-authored-by: Rijk van Zanten <rijkvanzanten@me.com>
This commit is contained in:
burka
2024-07-03 17:39:29 +02:00
committed by GitHub
parent 6628a3032a
commit c38d7d4897
6 changed files with 16 additions and 5 deletions

View File

@@ -0,0 +1,7 @@
---
'@directus/env': minor
'docs': minor
'@directus/api': minor
---
Added support for the ADMIN_TOKEN environment variable

View File

@@ -102,5 +102,7 @@ async function createDefaultAdmin(schema: SchemaOverview) {
logger.info(`No admin password provided. Defaulting to "${adminPassword}"`);
}
await usersService.createOne({ email: adminEmail, password: adminPassword, role, ...defaultAdminUser });
const token = env['ADMIN_TOKEN'] ?? null;
await usersService.createOne({ email: adminEmail, password: adminPassword, token, role, ...defaultAdminUser });
}

View File

@@ -76,7 +76,7 @@ which will create the database (file) for you.
::: tip Admin Account
Adding the `ADMIN_EMAIL` & `ADMIN_PASSWORD` to the `.env` file before running the `bootstrap` command, will populate the
admin user with the provided credentials instead of random values.
admin user with the provided credentials instead of random values. `ADMIN_TOKEN` sets the API token for the admin user.
:::

View File

@@ -42,9 +42,9 @@ Kubernetes configuration.
::: tip First User
You can use the `ADMIN_EMAIL` and `ADMIN_PASSWORD` environment variables to automatically provision the first user on
first creation using the `bootstrap` command. See [Environment Variables](/self-hosted/config-options#general) for more
information.
You can use the `ADMIN_EMAIL`, `ADMIN_PASSWORD` and `ADMIN_TOKEN` environment variables to automatically provision the
first user on first creation using the `bootstrap` command. See
[Environment Variables](/self-hosted/config-options#general) for more information.
:::

View File

@@ -1043,6 +1043,7 @@ variables to automatically configure the first user:
| ---------------- | ------------------------------------------------------------------------------------------------- | ------------- |
| `ADMIN_EMAIL` | The email address of the first user that's automatically created when using `directus bootstrap`. | -- |
| `ADMIN_PASSWORD` | The password of the first user that's automatically created when using `directus bootstrap`. | -- |
| `ADMIN_TOKEN` | The API token of the first user that's automatically created when using `directus bootstrap`. | -- |
## Telemetry

View File

@@ -220,6 +220,7 @@ export const DIRECTUS_VARIABLES = [
// admin account
'ADMIN_EMAIL',
'ADMIN_PASSWORD',
'ADMIN_TOKEN',
// telemetry
'TELEMETRY',