🛂 Add script for creating an initial admin key

This commit is contained in:
2023-06-30 22:35:16 +02:00
parent 6d4a8e760b
commit 108dbc98e8
2 changed files with 25 additions and 0 deletions

View File

@ -40,6 +40,12 @@ docker-compose logs -f
If everything is working, you should be able to connect to the app at http://localhost:3000 (or the IP address of your docker host)
To create an admin key for managing timetables or creating keys, you can use the `createAdminKey.js` script
```sh
docker compose exec app node /app/server/createAdminKey.js
```
## Setup for Development
To setup a development environment for Timetable V2, you will need to have NodeJS and Docker installed. (If you don't want to install Docker, you can also install PostgreSQL natively on your computer)
@ -86,3 +92,9 @@ Now you just need to install the dependencies and are ready to run the app:
npm install
node index.js
```
If you want to create an admin key, you can again use the `createAdminKey.js` script
```sh
node createAdminKey.js
```

13
server/createAdminKey.js Normal file
View File

@ -0,0 +1,13 @@
import Prisma from "@prisma/client";
const prisma = new Prisma.PrismaClient();
(async () => {
const key = await prisma.key.create({
data: {
permissions: ["admin"],
notes: `Created at ${new Date().toLocaleString()} using the "createAdminKeys.js" script`,
},
});
console.log("Created admin key:");
console.log(key.key);
})();