Skip to content

Commit

Permalink
Merge pull request #367 from amplication/auth-jwt-add-seed
Browse files Browse the repository at this point in the history
fix(plugins): add seed template to auth-jwt plugin
  • Loading branch information
morhag90 authored Mar 31, 2024
2 parents 6ef2933 + a76af9c commit 6546d71
Show file tree
Hide file tree
Showing 3 changed files with 116 additions and 25 deletions.
95 changes: 71 additions & 24 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion plugins/auth-jwt/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@amplication/plugin-auth-jwt",
"version": "1.4.12",
"version": "1.4.14",
"description": "set jwt as provider for Amplication build",
"main": "dist/index.js",
"nx": {},
Expand Down
44 changes: 44 additions & 0 deletions plugins/auth-jwt/src/templates/seed.template.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/***
* This file was auto-generated by Amplication and should not be modified by hand.
* The file will be re-generated with every new build, and all changes will be lost.
* To add a custom seed script, you can safely edit the content of ./customSeed.ts
***/

import * as dotenv from "dotenv";
import { PrismaClient } from "@prisma/client";
import { customSeed } from "./customSeed";

declare const DATA: { username: string };

if (require.main === module) {
dotenv.config();

const { BCRYPT_SALT } = process.env;

if (!BCRYPT_SALT) {
throw new Error("BCRYPT_SALT environment variable must be defined");
}

seed().catch((error) => {
console.error(error);
process.exit(1);
});
}

async function seed() {
console.info("Seeding database...");

const client = new PrismaClient();
const data = DATA;
await client.user.upsert({
where: { username: data.username },
update: {},
create: data,
});
void client.$disconnect();

console.info("Seeding database with custom seed...");
customSeed();

console.info("Seeded database successfully");
}

0 comments on commit 6546d71

Please sign in to comment.