Skip to content

Commit

Permalink
remove current user from createAuthResolver
Browse files Browse the repository at this point in the history
  • Loading branch information
manuelblum committed Nov 18, 2024
1 parent 305d888 commit 79a0f4e
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions src/v8/remove-current-user-from-auth-module.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { Project, SyntaxKind } from "ts-morph";

export default async function removeCurrentUserFromAuthModule() {
console.log("Remove Current User From Auth Module");

const project = new Project({ tsConfigFilePath: "./api/tsconfig.json" });
const sourceFiles = project.getSourceFiles("api/src/**/*.ts");
sourceFiles.forEach((sourceFile) => {
const createAuthResolverCall = sourceFile.getDescendantsOfKind(SyntaxKind.CallExpression).find((callExpression) => {
const expression = callExpression.getExpression();
return expression.getText() === "createAuthResolver";
});

if (createAuthResolverCall) {
const argument = createAuthResolverCall.getArguments()[0];
if (argument && argument.getKind() === SyntaxKind.ObjectLiteralExpression) {
const objectLiteral = argument.asKindOrThrow(SyntaxKind.ObjectLiteralExpression);
const currentUserProp = objectLiteral.getProperty("currentUser");
if (currentUserProp) {
console.log("Found createAuthResolver and removed currentUser in ", sourceFile.getFilePath());

currentUserProp.remove();
}
}
}
sourceFile.save();
});
}

0 comments on commit 79a0f4e

Please sign in to comment.