|
| 1 | +--- |
| 2 | +title: Migrate from 4.1.7 to 4.1.8 - Strapi Developer Docs |
| 3 | +description: Learn how you can migrate your Strapi application from 4.1.7 to 4.1.8. |
| 4 | +canonicalUrl: https://docs.strapi.io/developer-docs/latest/update-migration-guides/migration-guides/v4/migration-guide-4.0.x-to-4.1.8.html |
| 5 | +--- |
| 6 | + |
| 7 | +# v4.0.x to v4.1.8 migration guide |
| 8 | + |
| 9 | +The Strapi v4.0.x to v4.1.8 migration guide upgrades versions of v4.0.6 through v4.1.7 to v4.1.8. The minimum configuration for `config/admin` now includes the API token `API_TOKEN_SALT`. Strapi no longer populates default values for the admin JWT in `config/admin`. Initial values are generated and stored in the .env file during project creation. Strapi no longer passes secrets to non-development environments, requiring users to set the secrets purposefully. The migration to v4.1.8 consists of 4 steps: |
| 10 | + |
| 11 | +- upgrading the application dependencies |
| 12 | + |
| 13 | +## Upgrading the application dependencies to 4.1.8 |
| 14 | + |
| 15 | +:::prerequisites |
| 16 | +Stop the server before starting the upgrade. |
| 17 | +::: |
| 18 | + |
| 19 | +1. Upgrade all of the Strapi packages in the `package.json` to `4.1.8`: |
| 20 | + |
| 21 | +```jsx |
| 22 | +// path: package.json |
| 23 | + |
| 24 | +{ |
| 25 | + // ... |
| 26 | + "dependencies": { |
| 27 | + "@strapi/strapi": "4.1.8", |
| 28 | + "@strapi/plugin-users-permissions": "4.1.8", |
| 29 | + "@strapi/plugin-i18n": "4.1.8", |
| 30 | + "better-sqlite3": "7.4.6" |
| 31 | + // ... |
| 32 | + } |
| 33 | +} |
| 34 | + |
| 35 | +``` |
| 36 | + |
| 37 | +2. Save the edited `package.json` file. |
| 38 | + |
| 39 | +3. Run either `yarn` or `npm install` to install the new version. |
| 40 | + |
| 41 | +::: tip |
| 42 | +If the operation doesn't work, try removing your `yarn.lock` or `package-lock.json`. If that doesn't help, remove the `node_modules` folder as well and try again. |
| 43 | +::: |
| 44 | + |
| 45 | +## Fixing the breaking changes |
| 46 | + |
| 47 | +1. Modify the `config/admin` file. Strapi, by default, creates the environmental variable `API_TOKEN_SALT` and populates a unique value, stored in `/.env` at project creation. In order to update `config/admin`: |
| 48 | + |
| 49 | +- add the apiToken object, |
| 50 | +- remove the comma and default value from the `ADMIN_JWT_SECRET` parenthetical. |
| 51 | + |
| 52 | +<code-group> |
| 53 | + |
| 54 | +<code-block title="JAVASCRIPT"> |
| 55 | + |
| 56 | +```jsx |
| 57 | + |
| 58 | +//path: config/admin.js |
| 59 | + |
| 60 | +module.exports = ({ env }) => ({ |
| 61 | + auth: { |
| 62 | + secret: env('ADMIN_JWT_SECRET'), |
| 63 | + }, |
| 64 | + apiToken: { |
| 65 | + salt: env('API_TOKEN_SALT'), |
| 66 | + }, |
| 67 | +}); |
| 68 | + |
| 69 | +``` |
| 70 | + |
| 71 | +</code-block> |
| 72 | + |
| 73 | +<code-block title="TYPESCRIPT"> |
| 74 | + |
| 75 | +```jsx |
| 76 | +//path: config/admin.ts |
| 77 | + |
| 78 | +export default ({ env }) => ({ |
| 79 | + auth: { |
| 80 | + secret: env('ADMIN_JWT_SECRET'), |
| 81 | + }, |
| 82 | + apiToken: { |
| 83 | + salt: env('API_TOKEN_SALT'), |
| 84 | + }, |
| 85 | +}); |
| 86 | + |
| 87 | + |
| 88 | +``` |
| 89 | + |
| 90 | +</code-block> |
| 91 | + |
| 92 | +</code-group> |
| 93 | + |
| 94 | +2. Configure`JWT_SECRET`. `JWT_SECRET` is used by the Users and Permissions plugin, and populated in `/.env`. The property should be stored in `config/plugins.js` (or `config/plugins.ts` for a TypeScript project). The `plugins` file is not created by default in a Strapi application. If the file does not exist, users should create the file and add the following code snippet. |
| 95 | + |
| 96 | +<code-group> |
| 97 | + |
| 98 | +<code-block title="JAVASCRIPT"> |
| 99 | + |
| 100 | +```jsx |
| 101 | +// path: config/plugins.js |
| 102 | + |
| 103 | +module.exports = ({ env }) => ({ |
| 104 | + // ... |
| 105 | + 'users-permissions': { |
| 106 | + config: { |
| 107 | + jwtSecret: env('JWT_SECRET') |
| 108 | + }, |
| 109 | + }, |
| 110 | + // ... |
| 111 | +}); |
| 112 | + |
| 113 | +``` |
| 114 | + |
| 115 | +</code-block> |
| 116 | + |
| 117 | +<code-block title="TYPESCRIPT"> |
| 118 | + |
| 119 | +```jsx |
| 120 | +// path: config/plugins.ts |
| 121 | + |
| 122 | +export default ({ env }) => ({ |
| 123 | + // ... |
| 124 | + 'users-permissions': { |
| 125 | + config: { |
| 126 | + jwtSecret: env('JWT_SECRET') |
| 127 | + }, |
| 128 | + }, |
| 129 | + // ... |
| 130 | +}); |
| 131 | + |
| 132 | +``` |
| 133 | + |
| 134 | +</code-block> |
| 135 | + |
| 136 | +</code-group> |
| 137 | + |
| 138 | +## Setting secrets for non-development environments |
| 139 | + |
| 140 | +Users are required to set secrets for each unique environment, such as a production environment deployment on a platform. Strapi no longer passes the following secrets to non-development environments: |
| 141 | + |
| 142 | +- APP_KEYS |
| 143 | +- JWT_SECRET |
| 144 | +- API_TOKEN_SALT |
| 145 | +- ADMIN_JWT_SECRET |
| 146 | + |
| 147 | +There are multiple methods to generate secrets, for example running `openssl rand -base64 32` in the terminal (Mac and Linux OS). Generating unique secrets for each environment is recommended for increased security. |
| 148 | + |
| 149 | +::: caution |
| 150 | + |
| 151 | +The [Hosting Provider Guides](/developer-docs/latest/setup-deployment-guides/deployment.html#hosting-provider-guides.md) are being updated to reflect these changes. Community contributions updating the hosting guides are encouraged. |
| 152 | + |
| 153 | +::: |
| 154 | + |
| 155 | +!!!include(developer-docs/latest/update-migration-guides/migration-guides/v4/snippets/Rebuild-and-start-snippet.md)!!! |
0 commit comments