Skip to content
This repository was archived by the owner on Jun 28, 2025. It is now read-only.

Commit 46bc984

Browse files
committed
feat(cms): Add seed file with iterative user creation
1 parent fb6f357 commit 46bc984

File tree

2 files changed

+23
-2
lines changed

2 files changed

+23
-2
lines changed

cms/src/index.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { createUserSeed } from "./seed";
2+
13
export default {
24
/**
35
* An asynchronous register function that runs before
@@ -15,7 +17,6 @@ export default {
1517
* run jobs, or perform some special logic.
1618
*/
1719
async bootstrap ({ strapi }){
18-
// First, find the role by its name
1920
const user = {
2021
"username": "dummyUser",
2122
"email": "[email protected]",
@@ -32,7 +33,7 @@ export default {
3233
try{
3334
const count = await strapi.entityService.count("plugin::users-permissions.user")
3435
if(count ===0){
35-
await strapi.entityService.create("plugin::users-permissions.user", {data: user})
36+
createUserSeed(strapi, 10)
3637
console.log("SUCCESS: Created user on bootstrap")
3738
}
3839
else{

cms/src/seed.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
export async function createUserSeed(strapi, amountOfUsers: number){
2+
console.log("Function called")
3+
4+
for(let i = 0; i < amountOfUsers; i++){
5+
const user = {
6+
"username": `dummyUser${i}`,
7+
"email": `dummyUser${i}@example.com`,
8+
"provider": "local",
9+
"password": "dummyPassword",
10+
"resetPasswordToken": null,
11+
"confirmationToken": null,
12+
"confirmed": true,
13+
"blocked": false,
14+
"role": 1,
15+
"old_pw_hash": null,
16+
"migrated_pw": false
17+
}
18+
await strapi.entityService.create("plugin::users-permissions.user", {data: user})
19+
}
20+
}

0 commit comments

Comments
 (0)