Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(plugins): add seed template to auth-jwt plugin #367

Merged
merged 2 commits into from
Mar 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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");
}
Loading