Skip to content
Open
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
"@typescript-eslint/eslint-plugin": "^6.6.0",
"@typescript-eslint/parser": "^6.6.0",
"eslint": "^8.48.0",
"prettier": "^3.2.5",
"typescript": "^5.1.6"
}
}
9 changes: 9 additions & 0 deletions pnpm-lock.yaml

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

30 changes: 15 additions & 15 deletions src/commands/add/auth/clerk/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,9 @@
// 6. Add lib/auth/utils.ts
// 7. install package - @clerk/nextjs

import { consola } from "consola";
import {
addPackageToConfig,
createFile,
installPackages,
readConfigFile,
replaceFile,
updateConfigFile,
Expand All @@ -23,28 +21,30 @@ import {
} from "../../utils.js";
import { clerkGenerators } from "./generators.js";
import { formatFilePath, getFilePaths } from "../../../filePaths/index.js";
import { libAuthUtilsTs } from "../next-auth/generators.js";
import { updateTrpcWithSessionIfInstalled } from "../shared/index.js";

export const addClerk = async () => {
const { rootPath, preferredPackageManager, componentLib } = readConfigFile();
const { rootPath, componentLib } = readConfigFile();
const {
clerk: { middleware, signInPage, signUpPage },
shared: {
auth: { authUtils },
init,
},
} = getFilePaths();

const {
generateAuthUtilsTs,
generateMiddlewareTs,
generateSignInPageTs,
generateSignUpPageTs,
homePageWithUserButton,
} = clerkGenerators;
addContextProviderToAuthLayout("ClerkProvider");
addContextProviderToAppLayout("ClerkProvider");
addToDotEnv(

await addContextProviderToAuthLayout("ClerkProvider");
await addContextProviderToAppLayout("ClerkProvider");

await addToDotEnv(
[
{ key: "NEXT_PUBLIC_CLERK_PUBLISHABLE_KEY", value: "", public: true },
{ key: "CLERK_SECRET_KEY", value: "" },
Expand All @@ -55,29 +55,29 @@ export const addClerk = async () => {
],
rootPath
);
createFile(
await createFile(
formatFilePath(middleware, { prefix: "rootPath", removeExtension: false }),
generateMiddlewareTs()
);

createFile(
await createFile(
formatFilePath(signInPage, { removeExtension: false, prefix: "rootPath" }),
generateSignInPageTs()
);
createFile(
await createFile(
formatFilePath(signUpPage, { removeExtension: false, prefix: "rootPath" }),
generateSignUpPageTs()
);

replaceFile(
await replaceFile(
formatFilePath(init.dashboardRoute, {
removeExtension: false,
prefix: "rootPath",
}),
homePageWithUserButton(componentLib)
);

createFile(
await createFile(
formatFilePath(authUtils, {
prefix: "rootPath",
removeExtension: false,
Expand All @@ -86,15 +86,15 @@ export const addClerk = async () => {
);

// If trpc installed, add protectedProcedure
updateTrpcWithSessionIfInstalled();
await updateTrpcWithSessionIfInstalled();

addToInstallList({ regular: ["@clerk/nextjs"], dev: [] });
// await installPackages(
// { regular: "@clerk/nextjs", dev: "" },
// preferredPackageManager,
// );
addPackageToConfig("clerk");
updateConfigFile({ auth: "clerk" });
await addPackageToConfig("clerk");
await updateConfigFile({ auth: "clerk" });
// consola.success("Successfully added Clerk to your project!");
// consola.info(
// "Head over to https://dashboard.clerk.com/apps/new to create a new Clerk app"
Expand Down
9 changes: 5 additions & 4 deletions src/commands/add/auth/clerk/utils.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import fs from "fs";
import { createFile, replaceFile } from "../../../../utils.js";
import { replaceFile } from "../../../../utils.js";
import { formatFilePath, getFilePaths } from "../../../filePaths/index.js";

// export const updateClerkMiddlewareForStripe = (rootPath: string) => {
Expand All @@ -14,13 +14,14 @@ import { formatFilePath, getFilePaths } from "../../../filePaths/index.js";
// if (mwExists) {
// const mwContent = fs.readFileSync(mwPath, "utf-8");
// const newUtilsContent = mwContent.replace(initMWContent, updatedMWContent);
// replaceFile(mwPath, newUtilsContent);
// await replaceFile(mwPath, newUtilsContent);
// } else {
// console.error("Middleware does not exist");
// }
// };

export const addToClerkIgnoredRoutes = (newPath: string) => {
// TODO: Shouldn't this be "matcher" instead of "ignoredRoutes"?
export const addToClerkIgnoredRoutes = async (newPath: string) => {
const { clerk } = getFilePaths();
const initMWContent = "ignoredRoutes: [";
const updatedMWContent = "ignoredRoutes: [" + ` "${newPath}", `;
Expand All @@ -32,7 +33,7 @@ export const addToClerkIgnoredRoutes = (newPath: string) => {
if (mwExists) {
const mwContent = fs.readFileSync(mwPath, "utf-8");
const newUtilsContent = mwContent.replace(initMWContent, updatedMWContent);
replaceFile(mwPath, newUtilsContent);
await replaceFile(mwPath, newUtilsContent);
} else {
console.error("Middleware does not exist");
}
Expand Down
25 changes: 13 additions & 12 deletions src/commands/add/auth/kinde/index.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import { consola } from "consola";
import {
addPackageToConfig,
createFile,
installPackages,
readConfigFile,
updateConfigFile,
} from "../../../../utils.js";
Expand All @@ -20,33 +18,36 @@ import { addToInstallList } from "../../utils.js";

export const addKinde = async () => {
const { kinde, shared } = getFilePaths();
const { preferredPackageManager } = readConfigFile();

// add api route
createFile(
await createFile(
formatFilePath(kinde.routeHandler, {
prefix: "rootPath",
removeExtension: false,
}),
generateKindeRouteHandler()
);

// create signin button component
createFile(
await createFile(
formatFilePath(shared.auth.signInComponent, {
prefix: "rootPath",
removeExtension: false,
}),
generateSignInComponent()
);

// create auth/utils.ts
createFile(
await createFile(
formatFilePath(shared.auth.authUtils, {
prefix: "rootPath",
removeExtension: false,
}),
generateAuthUtils()
);

// update root page
createFile(
await createFile(
formatFilePath(shared.init.dashboardRoute, {
prefix: "rootPath",
removeExtension: false,
Expand All @@ -55,7 +56,7 @@ export const addKinde = async () => {
);

// generate sign in page
createFile(
await createFile(
formatFilePath(kinde.signInPage, {
prefix: "rootPath",
removeExtension: false,
Expand All @@ -64,10 +65,10 @@ export const addKinde = async () => {
);

// If trpc installed, add protectedProcedure
updateTrpcWithSessionIfInstalled();
await updateTrpcWithSessionIfInstalled();

// add env variables
addToDotEnv([
await addToDotEnv([
{
key: "KINDE_CLIENT_ID",
value: "",
Expand All @@ -91,7 +92,7 @@ export const addKinde = async () => {
// );
addToInstallList({ regular: ["@kinde-oss/kinde-auth-nextjs"], dev: [] });

addPackageToConfig("kinde");
updateConfigFile({ auth: "kinde" });
await addPackageToConfig("kinde");
await updateConfigFile({ auth: "kinde" });
// consola.success("Successfully installed Kinde auth");
};
33 changes: 16 additions & 17 deletions src/commands/add/auth/lucia/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,40 +56,39 @@ export const addLucia = async () => {
} else {
viewsAndComponents = generateViewsAndComponents(false);
}
createFile(
await createFile(
formatFilePath(lucia.signInPage, {
removeExtension: false,
prefix: "rootPath",
}),
viewsAndComponents.signInPage
);
createFile(
await createFile(
formatFilePath(lucia.signUpPage, {
removeExtension: false,
prefix: "rootPath",
}),
viewsAndComponents.signUpPage
);
createFile(
await createFile(
formatFilePath(lucia.formErrorComponent, {
removeExtension: false,
prefix: "rootPath",
}),
viewsAndComponents.authFormErrorComponent
);
replaceFile(
await replaceFile(
formatFilePath(shared.init.dashboardRoute, {
removeExtension: false,
prefix: "rootPath",
}),
viewsAndComponents.homePage
);
createFile(
await createFile(
rootPath.concat("app/loading.tsx"),
viewsAndComponents.loadingPage
);

createFile(
await createFile(
formatFilePath(lucia.signOutButtonComponent, {
removeExtension: false,
prefix: "rootPath",
Expand All @@ -98,7 +97,7 @@ export const addLucia = async () => {
);

// add server actions
createFile(
await createFile(
formatFilePath(lucia.usersActions, {
removeExtension: false,
prefix: "rootPath",
Expand All @@ -108,7 +107,7 @@ export const addLucia = async () => {

const authDirFiles = generateAuthDirFiles(orm, driver, provider);
// create auth/utils.ts
createFile(
await createFile(
formatFilePath(shared.auth.authUtils, {
removeExtension: false,
prefix: "rootPath",
Expand All @@ -117,7 +116,7 @@ export const addLucia = async () => {
);

// create auth/lucia.ts
createFile(
await createFile(
formatFilePath(lucia.libAuthLucia, {
removeExtension: false,
prefix: "rootPath",
Expand Down Expand Up @@ -176,15 +175,15 @@ export type UsernameAndPassword = z.infer<typeof authenticationSchema>;
/\.references\(\(\) => user\.id\)/g,
""
);
createFile(
await createFile(
formatFilePath(shared.auth.authSchema, {
removeExtension: false,
prefix: "rootPath",
}),
schemaWithoutReferences
);
} else {
createFile(
await createFile(
formatFilePath(shared.auth.authSchema, {
removeExtension: false,
prefix: "rootPath",
Expand Down Expand Up @@ -213,7 +212,7 @@ export type UsernameAndPassword = z.infer<typeof authenticationSchema>;
const contentsWithPool = contentsImportsUpdated.concat(
"\nexport const pool = new Pool({ connectionString: env.DATABASE_URL });"
);
replaceFile(dbTsPath, contentsWithPool);
await replaceFile(dbTsPath, contentsWithPool);
}

// install packages (lucia, and adapter) will have to pull in specific package
Expand All @@ -226,12 +225,12 @@ export type UsernameAndPassword = z.infer<typeof authenticationSchema>;

if (t3 && orm === "drizzle") {
// replace server/db/index.ts to have connection exported
updateDrizzleDbIndex(provider);
await updateDrizzleDbIndex(provider);
// updates to make sure shcmea is included in dbindex too
}

// If trpc installed, add protectedProcedure
updateTrpcWithSessionIfInstalled();
await updateTrpcWithSessionIfInstalled();

// update next config mjs
addNodeRsFlagsToNextConfig();
Expand All @@ -248,7 +247,7 @@ export type UsernameAndPassword = z.infer<typeof authenticationSchema>;
});

// add package to config
addPackageToConfig("lucia");
updateConfigFile({ auth: "lucia" });
await addPackageToConfig("lucia");
await updateConfigFile({ auth: "lucia" });
// consola.success("Successfully installed Lucia!");
};
Loading