Skip to content

Commit

Permalink
warn for incompat nextauth url and port
Browse files Browse the repository at this point in the history
  • Loading branch information
juliusmarminge committed Oct 15, 2023
1 parent e71bedd commit 7d26141
Show file tree
Hide file tree
Showing 10 changed files with 72 additions and 6 deletions.
7 changes: 1 addition & 6 deletions cli/src/helpers/createProject.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ export const createProject = async ({
scopedAppName,
noInstall,
appRouter,
packages,
});

// Install the selected packages
Expand All @@ -55,12 +56,6 @@ export const createProject = async ({

// Select necessary _app,index / layout,page files
if (appRouter) {
// Replace next.config
fs.copyFileSync(
path.join(PKG_ROOT, "template/extras/config/next-config-appdir.mjs"),
path.join(projectDir, "next.config.mjs")
);

selectLayoutFile({ projectDir, packages });
selectPageFile({ projectDir, packages });
} else {
Expand Down
11 changes: 11 additions & 0 deletions cli/src/helpers/scaffoldProject.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ export const scaffoldProject = async ({
projectDir,
pkgManager,
noInstall,
appRouter,
packages,
}: InstallerOptions) => {
const srcDir = path.join(PKG_ROOT, "template/base");

Expand Down Expand Up @@ -90,6 +92,15 @@ export const scaffoldProject = async ({
path.join(projectDir, ".gitignore")
);

// Select next.config.mjs
const configDir = path.join(PKG_ROOT, "template/extras/config/next-config");
let filename = packages?.nextAuth.inUse ? "with-auth-" : "with-";
filename += appRouter ? "appdir.mjs" : "pagedir.mjs";
fs.copyFileSync(
path.join(configDir, filename),
path.join(projectDir, "next.config.mjs")
);

const scaffoldedName =
projectName === "." ? "App" : chalk.cyan.bold(projectName);

Expand Down
2 changes: 2 additions & 0 deletions cli/template/base/src/env.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export const env = createEnv({
*/
server: {
NODE_ENV: z.enum(["development", "test", "production"]),
PORT: z.coerce.number().default(3000),
},

/**
Expand All @@ -25,6 +26,7 @@ export const env = createEnv({
*/
runtimeEnv: {
NODE_ENV: process.env.NODE_ENV,
PORT: process.env.PORT,
// NEXT_PUBLIC_CLIENTVAR: process.env.NEXT_PUBLIC_CLIENTVAR,
},
/**
Expand Down
20 changes: 20 additions & 0 deletions cli/template/extras/config/next-config/with-auth-appdir.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/**
* Run `build` or `dev` with `SKIP_ENV_VALIDATION` to skip env validation. This is especially useful
* for Docker builds.
*/
import { env } from "./src/env.mjs";

// Warn if local development URL doesn't match with the active port
if (
process.env.NODE_ENV === "development" &&
!env.NEXTAUTH_URL.includes(String(env.PORT))
) {
console.warn(
`NEXTAUTH_URL (${env.NEXTAUTH_URL}) doesn't match with PORT (${env.PORT})`
);
}

/** @type {import("next").NextConfig} */
const config = {};

export default config;
32 changes: 32 additions & 0 deletions cli/template/extras/config/next-config/with-auth-pagedir.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/**
* Run `build` or `dev` with `SKIP_ENV_VALIDATION` to skip env validation. This is especially useful
* for Docker builds.
*/
import { env } from "./src/env.mjs";

// Warn if local development URL doesn't match with the active port
if (
process.env.NODE_ENV === "development" &&
!env.NEXTAUTH_URL.includes(String(env.PORT))
) {
console.warn(
`NEXTAUTH_URL (${env.NEXTAUTH_URL}) doesn't match with PORT (${env.PORT})`
);
}

/** @type {import("next").NextConfig} */
const config = {
reactStrictMode: true,

/**
* If you are using `appDir` then you must comment the below `i18n` config out.
*
* @see https://github.com/vercel/next.js/issues/41980
*/
i18n: {
locales: ["en"],
defaultLocale: "en",
},
};

export default config;
File renamed without changes.
2 changes: 2 additions & 0 deletions cli/template/extras/src/env/with-auth-db.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export const env = createEnv({
NODE_ENV: z
.enum(["development", "test", "production"])
.default("development"),
PORT: z.coerce.number().default(3000),
NEXTAUTH_SECRET:
process.env.NODE_ENV === "production"
? z.string()
Expand Down Expand Up @@ -49,6 +50,7 @@ export const env = createEnv({
runtimeEnv: {
DATABASE_URL: process.env.DATABASE_URL,
NODE_ENV: process.env.NODE_ENV,
PORT: process.env.PORT,
NEXTAUTH_SECRET: process.env.NEXTAUTH_SECRET,
NEXTAUTH_URL: process.env.NEXTAUTH_URL,
DISCORD_CLIENT_ID: process.env.DISCORD_CLIENT_ID,
Expand Down
2 changes: 2 additions & 0 deletions cli/template/extras/src/env/with-auth.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export const env = createEnv({
NODE_ENV: z
.enum(["development", "test", "production"])
.default("development"),
PORT: z.coerce.number().default(3000),
NEXTAUTH_SECRET:
process.env.NODE_ENV === "production"
? z.string()
Expand Down Expand Up @@ -41,6 +42,7 @@ export const env = createEnv({
*/
runtimeEnv: {
NODE_ENV: process.env.NODE_ENV,
PORT: process.env.PORT,
NEXTAUTH_SECRET: process.env.NEXTAUTH_SECRET,
NEXTAUTH_URL: process.env.NEXTAUTH_URL,
DISCORD_CLIENT_ID: process.env.DISCORD_CLIENT_ID,
Expand Down
2 changes: 2 additions & 0 deletions cli/template/extras/src/env/with-db.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export const env = createEnv({
NODE_ENV: z
.enum(["development", "test", "production"])
.default("development"),
PORT: z.coerce.number().default(3000),
},

/**
Expand All @@ -35,6 +36,7 @@ export const env = createEnv({
runtimeEnv: {
DATABASE_URL: process.env.DATABASE_URL,
NODE_ENV: process.env.NODE_ENV,
PORT: process.env.PORT,
// NEXT_PUBLIC_CLIENTVAR: process.env.NEXT_PUBLIC_CLIENTVAR,
},
/**
Expand Down

0 comments on commit 7d26141

Please sign in to comment.