Skip to content

Commit

Permalink
Merge pull request #362 from amplication/fix/seed-auth-auth0
Browse files Browse the repository at this point in the history
refactor(auth): move auth-core seed event to auth plugins that need it
  • Loading branch information
mulygottlieb authored Mar 18, 2024
2 parents e16872b + cb66b51 commit c73f882
Show file tree
Hide file tree
Showing 20 changed files with 194 additions and 470 deletions.
1 change: 0 additions & 1 deletion libs/auth-core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
"peerDependencies": {
"@amplication/code-gen-types": "^2.0.23",
"@amplication/code-gen-utils": "^0.0.9",
"@babel/types": "7.24.0",
"ast-types": "0.14.2",
"dotenv": "16.3.2",
"lodash": "^4.17.21",
Expand Down
10 changes: 0 additions & 10 deletions libs/auth-core/src/auth-core-plugin.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { EventNames, Events } from "@amplication/code-gen-types";
import { AuthCorePlugin } from "./auth-core-plugin";
import {
afterCreateAppModule,
afterCreateSeed,
afterCreateServerAuth,
afterCreateServerPackageJson,
beforeCreateAppModule,
Expand All @@ -15,7 +14,6 @@ import {
beforeCreateEntityResolverToOneRelationMethods,
beforeCreateResolverBaseModule,
beforeCreateResolverModule,
beforeCreateSeed,
beforeCreateServer,
beforeCreateServerDotEnv,
beforeCreateServerPackageJson,
Expand Down Expand Up @@ -84,10 +82,6 @@ describe("AuthCorePlugin", () => {
CreateEntityResolverToOneRelationMethods: {
before: beforeCreateEntityResolverToOneRelationMethods,
},
CreateSeed: {
before: beforeCreateSeed,
after: afterCreateSeed,
},
CreateServer: {
before: beforeCreateServer,
},
Expand Down Expand Up @@ -136,10 +130,6 @@ describe("AuthCorePlugin", () => {
CreateEntityResolverToOneRelationMethods: {
before: beforeCreateEntityResolverToOneRelationMethods,
},
CreateSeed: {
before: beforeCreateSeed,
after: afterCreateSeed,
},
CreateServer: {
before: beforeCreateServer,
},
Expand Down
6 changes: 0 additions & 6 deletions libs/auth-core/src/auth-core-plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import {
} from "@amplication/code-gen-types";
import {
afterCreateAppModule,
afterCreateSeed,
afterCreateServerAuth,
beforeCreateAppModule,
beforeCreateEntityControllerModule,
Expand All @@ -15,7 +14,6 @@ import {
beforeCreateEntityResolverToOneRelationMethods,
beforeCreateResolverBaseModule,
beforeCreateResolverModule,
beforeCreateSeed,
beforeCreateServer,
beforeCreateServerDotEnv,
beforeCreateServerPackageJson,
Expand Down Expand Up @@ -70,10 +68,6 @@ export abstract class AuthCorePlugin implements AmplicationPlugin {
CreateEntityResolverToOneRelationMethods: {
before: beforeCreateEntityResolverToOneRelationMethods,
},
CreateSeed: {
before: beforeCreateSeed,
after: afterCreateSeed,
},
CreateServer: {
before: beforeCreateServer,
},
Expand Down
1 change: 0 additions & 1 deletion libs/auth-core/src/core/user-entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import {
EntityField,
EnumEntityPermissionType,
EnumEntityAction,
DsgContext,
} from "@amplication/code-gen-types";

export const USER_ENTITY_NAME = "User";
Expand Down
1 change: 0 additions & 1 deletion libs/auth-core/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ export * from "./events/create-entity-resolver-base";
export * from "./events/create-entity-resolver-to-many-relation-methods";
export * from "./events/create-entity-resolver-to-one-relation-methods";
export * from "./events/create-entity-resolver";
export * from "./events/create-seeds";
export * from "./events/create-server-app-module";
export * from "./events/create-server-auth";
export * from "./events/create-server-dotenv";
Expand Down
90 changes: 0 additions & 90 deletions libs/auth-core/src/tests/afterCreateSeed.spec.ts

This file was deleted.

8 changes: 4 additions & 4 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-basic/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@amplication/plugin-auth-basic",
"version": "1.4.11",
"version": "1.4.12",
"description": "set basic auth for Amplication build",
"main": "dist/index.js",
"nx": {},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,14 @@
import {
DsgContext,
CreateSeedParams,
ModuleMap,
} from "@amplication/code-gen-types";
import { CreateSeedParams, DsgContext } from "@amplication/code-gen-types";
import { addImports, importNames, interpolate } from "../util/ast";
import { builders, namedTypes } from "ast-types";
import { interpolate, importNames, addImports } from "../util/ast";
import {
BlockStatement,
IfStatement,
Statement,
FunctionDeclaration,
BlockStatement,
Statement,
Identifier,
TSTypeAnnotation,
} from "@babel/types";
import { resolve } from "path";
import { getStaticFiles } from "../util/file";

export async function beforeCreateSeed(
context: DsgContext,
Expand Down Expand Up @@ -175,18 +169,3 @@ export async function beforeCreateSeed(

return eventParams;
}

export async function afterCreateSeed(
context: DsgContext,
eventParams: CreateSeedParams,
modules: ModuleMap
): Promise<ModuleMap> {
const staticPath = resolve(__dirname, "./static/scripts");
const staticsFiles = await getStaticFiles(
context,
context.serverDirectories.scriptsDirectory,
staticPath
);
await modules.merge(staticsFiles);
return modules;
}
4 changes: 4 additions & 0 deletions plugins/auth-basic/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import {
AUTH_ENTITY_FIELD_PASSWORD,
AUTH_ENTITY_FIELD_USERNAME,
} from "./constants";
import { beforeCreateSeed } from "./events/createSeed";

const ARGS_ID = builders.identifier("args");
const PASSWORD_FIELD_ASYNC_METHODS = new Set(["create", "update"]);
Expand Down Expand Up @@ -61,6 +62,9 @@ class BasicAuthPlugin implements AmplicationPlugin {
CreateEntityServiceBase: {
before: this.beforeCreateEntityServiceBase,
},
CreateSeed: {
before: beforeCreateSeed,
},
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { parse } from "@amplication/code-gen-utils";
import { mock } from "jest-mock-extended";
import { prettyPrint } from "recast";
import { name } from "../../package.json";
import { beforeCreateSeed } from "../events/create-seeds";
import { beforeCreateSeed } from "../events/createSeed";

describe("Testing beforeCreateSeed hook", () => {
let context: DsgContext;
Expand Down
2 changes: 1 addition & 1 deletion plugins/auth-core/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@amplication/plugin-auth-core",
"version": "2.0.13",
"version": "2.0.14",
"description": "set auth for Amplication build",
"main": "dist/index.js",
"nx": {},
Expand Down
Loading

0 comments on commit c73f882

Please sign in to comment.