Skip to content

Commit

Permalink
Merge branch 'main' into neon-t3
Browse files Browse the repository at this point in the history
  • Loading branch information
JoseCToscano authored Dec 18, 2024
2 parents 2fbad83 + d22a0bf commit 7f00687
Show file tree
Hide file tree
Showing 83 changed files with 841 additions and 775 deletions.
12 changes: 6 additions & 6 deletions .github/workflows/e2e.yml
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,9 @@ jobs:
- run: cd ../ci-${{ matrix.trpc }}-${{ matrix.tailwind }}-${{ matrix.nextAuth }}-${{ matrix.prisma }}-${{ matrix.drizzle}}-${{ matrix.appRouter }}-${{ matrix.dbType }} && pnpm build
if: ${{ steps.matrix-valid.outputs.continue == 'true' }}
env:
NEXTAUTH_SECRET: foo
DISCORD_CLIENT_ID: bar
DISCORD_CLIENT_SECRET: baz
AUTH_SECRET: foo
AUTH_DISCORD_ID: bar
AUTH_DISCORD_SECRET: baz
SKIP_ENV_VALIDATION: true

build-t3-app-with-bun:
Expand Down Expand Up @@ -101,7 +101,7 @@ jobs:
- run: cd ../ci-bun && bun run build
# - run: cd ../ci-bun && bun --bun run build
env:
NEXTAUTH_SECRET: foo
AUTH_SECRET: foo
AUTH_DISCORD_ID: bar
AUTH_DISCORD_SECRET: baz
DATABASE_URL: mysql://root:root@localhost:3306/test # can't use url from example env cause we block that in t3-env
DISCORD_CLIENT_ID: bar
DISCORD_CLIENT_SECRET: baz
7 changes: 7 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
{
"workbench.colorCustomizations": {
"titleBar.activeBackground": "#1f0d49",
"titleBar.activeForeground": "#e2e8f0",
"titleBar.inactiveBackground": "#181239",
"titleBar.inactiveForeground": "#b1b6bd"
},

"editor.codeActionsOnSave": {
"source.fixAll.eslint": "explicit"
},
Expand Down
22 changes: 22 additions & 0 deletions cli/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,27 @@
# Changelog

## 7.38.1

### Patch Changes

- [#2010](https://github.com/t3-oss/create-t3-app/pull/2010) [`12fccae15d08bc11168fe6b462d978a6787b5c7c`](https://github.com/t3-oss/create-t3-app/commit/12fccae15d08bc11168fe6b462d978a6787b5c7c) Thanks [@swyckoff](https://github.com/swyckoff)! - Added an import for crypto in the cli envVars.ts to support older node versions.

## 7.38.0

### Minor Changes

- [#2000](https://github.com/t3-oss/create-t3-app/pull/2000) [`41de302b5a76966741d1dc270ba5da27064f82e8`](https://github.com/t3-oss/create-t3-app/commit/41de302b5a76966741d1dc270ba5da27064f82e8) Thanks [@ronanru](https://github.com/ronanru)! - update to next.js 15 and next-auth v5

- [#2002](https://github.com/t3-oss/create-t3-app/pull/2002) [`54b66484692b76d325f59dc233eb27e0aee59af2`](https://github.com/t3-oss/create-t3-app/commit/54b66484692b76d325f59dc233eb27e0aee59af2) Thanks [@devotoare](https://github.com/devotoare)! - Change drizzle with PostgresQL to use identity columns

### Patch Changes

- [#1969](https://github.com/t3-oss/create-t3-app/pull/1969) [`e08dbe307b4e37c7cc7e0cbf6243c008771ef4f8`](https://github.com/t3-oss/create-t3-app/commit/e08dbe307b4e37c7cc7e0cbf6243c008771ef4f8) Thanks [@Guria](https://github.com/Guria)! - fix issue with prefetch protected procedure in auth templates

- [#1997](https://github.com/t3-oss/create-t3-app/pull/1997) [`fe85a233c62af607e8a39bf5ca1b2358d43c6587`](https://github.com/t3-oss/create-t3-app/commit/fe85a233c62af607e8a39bf5ca1b2358d43c6587) Thanks [@programming-with-ia](https://github.com/programming-with-ia)! - Add more scripts in `package.json`

- [#1975](https://github.com/t3-oss/create-t3-app/pull/1975) [`78cb06f99f15f4f4f90b57e3545f1dc0b222eaf3`](https://github.com/t3-oss/create-t3-app/commit/78cb06f99f15f4f4f90b57e3545f1dc0b222eaf3) Thanks [@0pilatos0](https://github.com/0pilatos0)! - Resolved issue where database startup script did not check for docker daemon being up and running

## 7.37.0

### Minor Changes
Expand Down
2 changes: 1 addition & 1 deletion cli/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "create-t3-app",
"version": "7.37.0",
"version": "7.38.1",
"description": "Create web application with the t3 stack",
"license": "MIT",
"repository": {
Expand Down
6 changes: 6 additions & 0 deletions cli/src/helpers/logNextSteps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,12 @@ export const logNextSteps = async ({
}
}

if (packages?.nextAuth.inUse) {
logger.info(
` Fill in your .env with necessary values. See https://create.t3.gg/en/usage/first-steps for more info.`
);
}

if (["npm", "bun"].includes(pkgManager)) {
logger.info(` ${pkgManager} run dev`);
} else {
Expand Down
14 changes: 12 additions & 2 deletions cli/src/installers/dbContainer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,13 @@ import { PKG_ROOT } from "~/consts.js";
import { type Installer } from "~/installers/index.js";
import { parseNameAndPath } from "~/utils/parseNameAndPath.js";

// Sanitizes a project name to ensure it adheres to Docker container naming conventions.
const sanitizeName = (name: string): string => {
return name
.replace(/[^a-zA-Z0-9_.-]/g, "_") // Replace invalid characters with underscores
.toLowerCase(); // Convert to lowercase for consistency
};

export const dbContainerInstaller: Installer = ({
projectDir,
databaseProvider,
Expand All @@ -18,11 +25,14 @@ export const dbContainerInstaller: Installer = ({
const scriptDest = path.join(projectDir, "start-database.sh");
// for configuration with postgresql and mysql when project is created with '.' project name
const [projectNameParsed] =
projectName == "." ? parseNameAndPath(projectDir) : [projectName];
projectName === "." ? parseNameAndPath(projectDir) : [projectName];

// Sanitize the project name for Docker container usage
const sanitizedProjectName = sanitizeName(projectNameParsed);

fs.writeFileSync(
scriptDest,
scriptText.replaceAll("project1", projectNameParsed)
scriptText.replaceAll("project1", sanitizedProjectName)
);
fs.chmodSync(scriptDest, "755");
};
6 changes: 3 additions & 3 deletions cli/src/installers/dependencyVersionMap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
*/
export const dependencyVersionMap = {
// NextAuth.js
"next-auth": "^4.24.7",
"@auth/prisma-adapter": "^1.6.0",
"@auth/drizzle-adapter": "^1.1.0",
"next-auth": "5.0.0-beta.25",
"@auth/prisma-adapter": "^2.7.2",
"@auth/drizzle-adapter": "^1.7.2",

// Prisma
prisma: "^5.14.0",
Expand Down
43 changes: 27 additions & 16 deletions cli/src/installers/envVars.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import crypto from "node:crypto";
import path from "path";
import fs from "fs-extra";

Expand Down Expand Up @@ -51,8 +52,19 @@ export const envVariablesInstaller: Installer = ({
const envDest = path.join(projectDir, ".env");
const envExampleDest = path.join(projectDir, ".env.example");

fs.writeFileSync(envDest, envContent, "utf-8");
fs.writeFileSync(envExampleDest, exampleEnvContent + envContent, "utf-8");
const _exampleEnvContent = exampleEnvContent + envContent;

// Generate an auth secret and put in .env, not .env.example
const secret = Buffer.from(
crypto.getRandomValues(new Uint8Array(32))
).toString("base64");
const _envContent = envContent.replace(
'AUTH_SECRET=""',
`AUTH_SECRET="${secret}" # Generated by create-t3-app.`
);

fs.writeFileSync(envDest, _envContent, "utf-8");
fs.writeFileSync(envExampleDest, _exampleEnvContent, "utf-8");
};

const getEnvContent = (
Expand All @@ -69,6 +81,19 @@ const getEnvContent = (
.trim()
.concat("\n");

if (usingAuth)
content += `
# Next Auth
# You can generate a new secret on the command line with:
# npx auth secret
# https://next-auth.js.org/configuration/options#secret
AUTH_SECRET=""
# Next Auth Discord Provider
AUTH_DISCORD_ID=""
AUTH_DISCORD_SECRET=""
`;

if (usingPrisma)
content += `
# Prisma
Expand Down Expand Up @@ -101,20 +126,6 @@ DATABASE_URL="postgresql://YOUR_POSTGRES_CONNECTION_STRING_HERE?sslmode=require"
content += "\n";
}

if (usingAuth)
content += `
# Next Auth
# You can generate a new secret on the command line with:
# openssl rand -base64 32
# https://next-auth.js.org/configuration/options#secret
# NEXTAUTH_SECRET=""
NEXTAUTH_URL="http://localhost:3000"
# Next Auth Discord Provider
DISCORD_CLIENT_ID=""
DISCORD_CLIENT_SECRET=""
`;

if (!usingAuth && !usingPrisma)
content += `
# Example:
Expand Down
23 changes: 10 additions & 13 deletions cli/src/installers/nextAuth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,7 @@ import { type AvailableDependencies } from "~/installers/dependencyVersionMap.js
import { type Installer } from "~/installers/index.js";
import { addPackageDependency } from "~/utils/addPackageDependency.js";

export const nextAuthInstaller: Installer = ({
projectDir,
packages,
appRouter,
}) => {
export const nextAuthInstaller: Installer = ({ projectDir, packages }) => {
const usingPrisma = packages?.prisma.inUse;
const usingDrizzle = packages?.drizzle.inUse;

Expand All @@ -26,25 +22,26 @@ export const nextAuthInstaller: Installer = ({

const extrasDir = path.join(PKG_ROOT, "template/extras");

const apiHandlerFile = "src/pages/api/auth/[...nextauth].ts";
const routeHandlerFile = "src/app/api/auth/[...nextauth]/route.ts";
const srcToUse = appRouter ? routeHandlerFile : apiHandlerFile;
const apiHandlerFile = "src/app/api/auth/[...nextauth]/route.ts";

const apiHandlerSrc = path.join(extrasDir, srcToUse);
const apiHandlerDest = path.join(projectDir, srcToUse);
const apiHandlerSrc = path.join(extrasDir, apiHandlerFile);
const apiHandlerDest = path.join(projectDir, apiHandlerFile);

const authConfigSrc = path.join(
extrasDir,
"src/server",
appRouter ? "auth-app" : "auth-pages",
"src/server/auth/config",
usingPrisma
? "with-prisma.ts"
: usingDrizzle
? "with-drizzle.ts"
: "base.ts"
);
const authConfigDest = path.join(projectDir, "src/server/auth.ts");
const authConfigDest = path.join(projectDir, "src/server/auth/config.ts");

const authIndexSrc = path.join(extrasDir, "src/server/auth/index.ts");
const authIndexDest = path.join(projectDir, "src/server/auth/index.ts");

fs.copySync(apiHandlerSrc, apiHandlerDest);
fs.copySync(authConfigSrc, authConfigDest);
fs.copySync(authIndexSrc, authIndexDest);
};
18 changes: 16 additions & 2 deletions cli/src/installers/tailwind.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import path from "path";
import fs from "fs-extra";
import { type PackageJson } from "type-fest";

import { PKG_ROOT } from "~/consts.js";
import { type Installer } from "~/installers/index.js";
Expand All @@ -22,17 +23,30 @@ export const tailwindInstaller: Installer = ({ projectDir }) => {
const twCfgSrc = path.join(extrasDir, "config/tailwind.config.ts");
const twCfgDest = path.join(projectDir, "tailwind.config.ts");

const postcssCfgSrc = path.join(extrasDir, "config/postcss.config.cjs");
const postcssCfgDest = path.join(projectDir, "postcss.config.cjs");
const postcssCfgSrc = path.join(extrasDir, "config/postcss.config.js");
const postcssCfgDest = path.join(projectDir, "postcss.config.js");

const prettierSrc = path.join(extrasDir, "config/_prettier.config.js");
const prettierDest = path.join(projectDir, "prettier.config.js");

const cssSrc = path.join(extrasDir, "src/styles/globals.css");
const cssDest = path.join(projectDir, "src/styles/globals.css");

// add format:* scripts to package.json
const packageJsonPath = path.join(projectDir, "package.json");

const packageJsonContent = fs.readJSONSync(packageJsonPath) as PackageJson;
packageJsonContent.scripts = {
...packageJsonContent.scripts,
"format:write": 'prettier --write "**/*.{ts,tsx,js,jsx,mdx}" --cache',
"format:check": 'prettier --check "**/*.{ts,tsx,js,jsx,mdx}" --cache',
};

fs.copySync(twCfgSrc, twCfgDest);
fs.copySync(postcssCfgSrc, postcssCfgDest);
fs.copySync(cssSrc, cssDest);
fs.copySync(prettierSrc, prettierDest);
fs.writeJSONSync(packageJsonPath, packageJsonContent, {
spaces: 2,
});
};
2 changes: 1 addition & 1 deletion cli/template/base/next.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* Run `build` or `dev` with `SKIP_ENV_VALIDATION` to skip env validation. This is especially useful
* for Docker builds.
*/
await import("./src/env.js");
import "./src/env.js";

/** @type {import("next").NextConfig} */
const config = {
Expand Down
12 changes: 8 additions & 4 deletions cli/template/base/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,19 @@
"type": "module",
"private": true,
"scripts": {
"dev": "next dev",
"dev": "next dev --turbo",
"build": "next build",
"start": "next start",
"lint": "next lint"
"lint": "next lint",
"lint:fix": "next lint --fix",
"check": "next lint && tsc --noEmit",
"preview": "next build && next start",
"typecheck": "tsc --noEmit"
},
"dependencies": {
"@t3-oss/env-nextjs": "^0.10.1",
"geist": "^1.3.0",
"next": "^14.2.4",
"next": "^15.0.1",
"react": "^18.3.1",
"react-dom": "^18.3.1",
"zod": "^3.23.3"
Expand All @@ -25,7 +29,7 @@
"@typescript-eslint/eslint-plugin": "^8.1.0",
"@typescript-eslint/parser": "^8.1.0",
"eslint": "^8.57.0",
"eslint-config-next": "^14.2.4",
"eslint-config-next": "^15.0.1",
"typescript": "^5.5.3"
}
}
4 changes: 1 addition & 3 deletions cli/template/extras/config/_prettier.config.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
/** @type {import('prettier').Config & import('prettier-plugin-tailwindcss').PluginOptions} */
const config = {
export default {
plugins: ["prettier-plugin-tailwindcss"],
};

export default config;
2 changes: 1 addition & 1 deletion cli/template/extras/config/next-config-appdir.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* Run `build` or `dev` with `SKIP_ENV_VALIDATION` to skip env validation. This is especially useful
* for Docker builds.
*/
await import("./src/env.js");
import "./src/env.js";

/** @type {import("next").NextConfig} */
const config = {};
Expand Down
7 changes: 0 additions & 7 deletions cli/template/extras/config/postcss.config.cjs

This file was deleted.

5 changes: 5 additions & 0 deletions cli/template/extras/config/postcss.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export default {
plugins: {
tailwindcss: {},
},
};
8 changes: 2 additions & 6 deletions cli/template/extras/src/app/api/auth/[...nextauth]/route.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
import NextAuth from "next-auth";
import { handlers } from "~/server/auth";

import { authOptions } from "~/server/auth";

// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
const handler = NextAuth(authOptions);
export { handler as GET, handler as POST };
export const { GET, POST } = handlers;
8 changes: 5 additions & 3 deletions cli/template/extras/src/app/page/with-auth-trpc-tw.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
import Link from "next/link";

import { LatestPost } from "~/app/_components/post";
import { getServerAuthSession } from "~/server/auth";
import { auth } from "~/server/auth";
import { api, HydrateClient } from "~/trpc/server";

export default async function Home() {
const hello = await api.post.hello({ text: "from tRPC" });
const session = await getServerAuthSession();
const session = await auth();

void api.post.getLatest.prefetch();
if (session?.user) {
void api.post.getLatest.prefetch();
}

return (
<HydrateClient>
Expand Down
Loading

0 comments on commit 7f00687

Please sign in to comment.