|
1 | 1 | module.exports = { |
2 | 2 | async bootstrap({ strapi }) { |
3 | | - console.log('🚀 Bootstrap function called!'); |
4 | | - // TODO: clean up this boostrap script |
5 | | - // Only run seeding in development/test environments |
6 | | - if (process.env.NODE_ENV !== 'production') { |
7 | | - try { |
8 | | - console.log('🌱 Starting bootstrap seeding...'); |
| 3 | + try { |
| 4 | + console.log('🚀 Starting seeding...'); |
9 | 5 |
|
10 | | - // Check if admin user exists |
11 | | - const adminUser = await strapi.query('admin::user').findOne({ |
12 | | - where: { email: '[email protected]' } |
13 | | - }); |
14 | | - |
15 | | - if (!adminUser) { |
16 | | - // Create admin user using Strapi's admin service |
17 | | - const adminUserService = strapi.service('admin::user'); |
18 | | - const superAdminRole = await strapi.query('admin::role').findOne({ |
19 | | - where: { code: 'strapi-super-admin' } |
20 | | - }); |
| 6 | + // Check if admin user exists |
| 7 | + const adminUser = await strapi.query('admin::user').findOne({ |
| 8 | + where: { email: '[email protected]' } |
| 9 | + }); |
21 | 10 |
|
22 | | - await adminUserService.create({ |
23 | | - firstname: 'Super Admin User', |
24 | | - |
25 | | - password: 'password', |
26 | | - isActive: true, |
27 | | - roles: [superAdminRole.id], |
28 | | - }); |
29 | | - console.log('✅ Admin user created'); |
30 | | - } else { |
31 | | - console.log('✅ Admin user already exists'); |
32 | | - // Update the password if it's not hashed (for existing users) |
33 | | - if (adminUser.password === 'password') { |
34 | | - const adminUserService = strapi.service('admin::user'); |
35 | | - await adminUserService.updateById(adminUser.id, { |
36 | | - password: 'password' |
37 | | - }); |
38 | | - console.log('✅ Admin user password updated with proper hash'); |
39 | | - } |
40 | | - } |
41 | | - |
42 | | - // Check if test API token exists |
43 | | - const existingToken = await strapi.query('admin::api-token').findOne({ |
44 | | - where: { name: 'cypress-test-token' } |
| 11 | + if (!adminUser) { |
| 12 | + // Create admin user using Strapi's admin service |
| 13 | + const adminUserService = strapi.service('admin::user'); |
| 14 | + const superAdminRole = await strapi.query('admin::role').findOne({ |
| 15 | + where: { code: 'strapi-super-admin' } |
45 | 16 | }); |
46 | 17 |
|
47 | | - if (!existingToken) { |
48 | | - // Create API token for Cypress tests |
49 | | - const tokenService = strapi.service('admin::api-token'); |
50 | | - const token = await tokenService.create({ |
51 | | - name: 'cypress-test-token', |
52 | | - description: 'API token for Cypress tests', |
53 | | - type: 'full-access', |
| 18 | + await adminUserService.create({ |
| 19 | + firstname: 'Super Admin User', |
| 20 | + |
| 21 | + password: 'password', |
| 22 | + isActive: true, |
| 23 | + roles: [superAdminRole.id], |
| 24 | + }); |
| 25 | + console.log('✅ Admin user created'); |
| 26 | + } else { |
| 27 | + console.log('✅ Admin user already exists'); |
| 28 | + // Update the password if it's not hashed (for existing users) |
| 29 | + if (adminUser.password === 'password') { |
| 30 | + const adminUserService = strapi.service('admin::user'); |
| 31 | + await adminUserService.updateById(adminUser.id, { |
| 32 | + password: 'password' |
54 | 33 | }); |
55 | | - console.log('✅ Cypress test token created:', token.accessKey); |
56 | | - } else { |
57 | | - console.log('✅ Cypress test token already exists'); |
| 34 | + console.log('✅ Admin user password updated with proper hash'); |
58 | 35 | } |
59 | | - |
60 | | - console.log('🌱 Bootstrap seeding completed successfully'); |
61 | | - } catch (error) { |
62 | | - console.error('❌ Bootstrap seeding failed:', error.message); |
63 | | - console.error('Error details:', error); |
64 | 36 | } |
| 37 | + |
| 38 | + console.log('🌱 Seeding completed!'); |
| 39 | + } catch (error) { |
| 40 | + console.error('❌ Seeding failed:', error.message); |
| 41 | + console.error('Error details:', error); |
65 | 42 | } |
66 | 43 | }, |
67 | 44 | }; |
0 commit comments