This repository was archived by the owner on Jun 28, 2025. It is now read-only.
File tree Expand file tree Collapse file tree 4 files changed +17793
-1125
lines changed Expand file tree Collapse file tree 4 files changed +17793
-1125
lines changed Original file line number Diff line number Diff line change
1
+ import { Strapi } from "@strapi/strapi" ;
2
+
3
+ export async function seedUsers ( strapi :Strapi ) {
4
+ const amountOfUsers = 10 ;
5
+ try {
6
+ const count = await strapi . entityService . count ( "plugin::users-permissions.user" ) ;
7
+ if ( count === 0 ) {
8
+ for ( let i = 0 ; i < amountOfUsers ; i ++ ) {
9
+ const user = {
10
+ username : `dummyUser${ i } ` ,
11
+ email : `dummyUser${ i } @example.com` ,
12
+ provider : "local" ,
13
+ password : "dummyPassword" ,
14
+ resetPasswordToken : null ,
15
+ confirmationToken : null ,
16
+ confirmed : true ,
17
+ blocked : false ,
18
+ role : 1 ,
19
+ old_pw_hash : null ,
20
+ migrated_pw : false ,
21
+ } ;
22
+ await strapi . entityService . create ( "plugin::users-permissions.user" , { data : user } ) ;
23
+ }
24
+ console . log ( "SUCCESS: Created user on bootstrap" ) ;
25
+ } else {
26
+ console . log ( "INFO: User have already been created on bootstrap" ) ;
27
+ }
28
+ } catch ( err ) {
29
+ console . log ( "ERROR: Could not create users on bootstrap" ) ;
30
+ console . log ( err ) ;
31
+ }
32
+ }
Original file line number Diff line number Diff line change
1
+ import { seedUsers } from "./config/seed/users" ;
2
+
1
3
export default {
2
4
/**
3
5
* An asynchronous register function that runs before
@@ -15,33 +17,8 @@ export default {
15
17
* run jobs, or perform some special logic.
16
18
*/
17
19
async bootstrap ( { strapi } ) {
18
- const amountOfUsers = 10 ;
19
- try {
20
- const count = await strapi . entityService . count ( "plugin::users-permissions.user" ) ;
21
- if ( count === 0 ) {
22
- for ( let i = 0 ; i < amountOfUsers ; i ++ ) {
23
- const user = {
24
- username : `dummyUser${ i } ` ,
25
- email : `dummyUser${ i } @example.com` ,
26
- provider : "local" ,
27
- password : "dummyPassword" ,
28
- resetPasswordToken : null ,
29
- confirmationToken : null ,
30
- confirmed : true ,
31
- blocked : false ,
32
- role : 1 ,
33
- old_pw_hash : null ,
34
- migrated_pw : false ,
35
- } ;
36
- await strapi . entityService . create ( "plugin::users-permissions.user" , { data : user } ) ;
37
- }
38
- console . log ( "SUCCESS: Created user on bootstrap" ) ;
39
- } else {
40
- console . log ( "INFO: User have already been created on bootstrap" ) ;
41
- }
42
- } catch ( err ) {
43
- console . log ( "ERROR: Could not create user on bootstrap" ) ;
44
- console . log ( err ) ;
20
+ if ( process . env . NODE_ENV === "development" ) {
21
+ seedUsers ( strapi ) ;
45
22
}
46
23
} ,
47
24
} ;
You can’t perform that action at this time.
0 commit comments