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

Commit fb6f357

Browse files
committed
feat(cms/index.ts): Add seeding of user on bootstrap
1 parent 85062fe commit fb6f357

File tree

2 files changed

+31
-1
lines changed

2 files changed

+31
-1
lines changed

cms/src/index.ts

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,34 @@ export default {
1414
* This gives you an opportunity to set up your data model,
1515
* run jobs, or perform some special logic.
1616
*/
17-
bootstrap(/*{ strapi }*/) {},
17+
async bootstrap ({ strapi }){
18+
// First, find the role by its name
19+
const user = {
20+
"username": "dummyUser",
21+
"email": "[email protected]",
22+
"provider": "local",
23+
"password": "dummyPassword",
24+
"resetPasswordToken": null,
25+
"confirmationToken": null,
26+
"confirmed": true,
27+
"blocked": false,
28+
"role": 1,
29+
"old_pw_hash": null,
30+
"migrated_pw": false
31+
}
32+
try{
33+
const count = await strapi.entityService.count("plugin::users-permissions.user")
34+
if(count ===0){
35+
await strapi.entityService.create("plugin::users-permissions.user", {data: user})
36+
console.log("SUCCESS: Created user on bootstrap")
37+
}
38+
else{
39+
console.log("INFO: User have already been created on bootstrap")
40+
}
41+
}
42+
catch(err){
43+
console.log("ERROR: Could not create user on bootstrap")
44+
console.log(err.details)
45+
}
46+
}
1847
};

cms/tsconfig.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
{
22
"extends": "@strapi/typescript-utils/tsconfigs/server",
33
"compilerOptions": {
4+
"lib": ["ES2015", "dom"],
45
"outDir": "dist",
56
"rootDir": "."
67
},

0 commit comments

Comments
 (0)