Compare commits

...

25 Commits

Author SHA1 Message Date
3370ab6a03 added spinner to signin button
All checks were successful
Vercel Production Deployment / Deploy-Production (push) Successful in 2m28s
2024-05-17 23:22:31 +02:00
6f18a4cb48 fixed css
All checks were successful
Vercel Production Deployment / Deploy-Production (push) Successful in 2m8s
2024-05-17 11:31:09 +02:00
2999c79995 and typo
All checks were successful
Vercel Production Deployment / Deploy-Production (push) Successful in 2m12s
2024-05-17 11:21:51 +02:00
9b32a5e8bb typo
Some checks failed
Vercel Production Deployment / Deploy-Production (push) Has been cancelled
2024-05-17 11:21:12 +02:00
89e39240a1 Merge branch 'main' of https://gitea.rannes.dev/rannes.dev/titles
Some checks failed
Vercel Production Deployment / Deploy-Production (push) Has been cancelled
2024-05-17 11:20:53 +02:00
8daa0f4032 updated readme 2024-05-17 11:20:51 +02:00
fc33072e84 Merge pull request 'Set up next-theme and dark mode with toggle example' (#5) from next-themes into main
Some checks failed
Vercel Production Deployment / Deploy-Production (push) Failing after 48s
Reviewed-on: #5
2024-05-17 09:16:36 +00:00
6dd60de8f4 Set up next-theme and dark mode with toggle example
All checks were successful
Vercel Preview Deployment / Deploy-Preview (push) Successful in 2m7s
2024-05-17 11:16:20 +02:00
77b60eda84 Merge pull request 'added darkmode class in tailwind conf' (#4) from framer-nextui into main
All checks were successful
Vercel Production Deployment / Deploy-Production (push) Successful in 2m2s
Vercel Preview Deployment / Deploy-Preview (push) Successful in 2m8s
Reviewed-on: #4
2024-05-17 09:02:52 +00:00
8a4d912202 added darkmode class in tailwind conf
All checks were successful
Vercel Preview Deployment / Deploy-Preview (push) Successful in 2m23s
2024-05-17 11:02:07 +02:00
1b2ab0aa1b Merge pull request 'set up nextui and framer motion' (#3) from framer-nextui into main
All checks were successful
Vercel Production Deployment / Deploy-Production (push) Successful in 1m51s
Reviewed-on: #3
2024-05-17 08:45:25 +00:00
3c39510aa3 set up nextui and framer motion
All checks were successful
Vercel Preview Deployment / Deploy-Preview (push) Successful in 2m15s
2024-05-17 10:44:41 +02:00
94918c229f Merge pull request 'authjs' (#2) from authjs into main
All checks were successful
Vercel Production Deployment / Deploy-Production (push) Successful in 2m25s
Vercel Preview Deployment / Deploy-Preview (push) Successful in 2m10s
Reviewed-on: #2
2024-05-16 21:42:41 +00:00
fab52dbfaf working in development
All checks were successful
Vercel Preview Deployment / Deploy-Preview (push) Successful in 1m36s
2024-05-16 23:23:10 +02:00
3429f35b95 working in dev mod. The issue was that my app url had http and the callback had https
All checks were successful
Vercel Preview Deployment / Deploy-Preview (push) Successful in 2m19s
2024-05-16 22:08:11 +02:00
82fa5d0024 added signin button.
All checks were successful
Vercel Preview Deployment / Deploy-Preview (push) Successful in 2m36s
keep getting redirect url error
2024-05-16 21:58:14 +02:00
85e128312e changed image src for testing purposes
All checks were successful
Vercel Production Deployment / Deploy-Production (push) Successful in 2m1s
Vercel Preview Deployment / Deploy-Preview (push) Successful in 2m10s
2024-05-16 15:57:14 +02:00
c39bf2fcc1 got drizzle working. The error was the query.
All checks were successful
Vercel Production Deployment / Deploy-Production (push) Successful in 1m37s
2024-05-16 15:29:41 +02:00
98ffb58cdb added drizzle and connected to vercel
All checks were successful
Vercel Production Deployment / Deploy-Production (push) Successful in 2m21s
2024-05-16 14:37:35 +02:00
8b2feffb1e purge 2.0
All checks were successful
Vercel Production Deployment / Deploy-Production (push) Successful in 1m28s
2024-05-16 13:44:35 +02:00
ce6d64ce02 purge
Some checks failed
Vercel Production Deployment / Deploy-Production (push) Failing after 48s
2024-05-16 13:40:11 +02:00
924640d89f moved env variables to vercel
All checks were successful
Vercel Production Deployment / Deploy-Production (push) Successful in 1m39s
2024-05-13 17:53:11 +02:00
27882128fe cleaned up
All checks were successful
Vercel Production Deployment / Deploy-Production (push) Successful in 1m51s
2024-05-13 17:50:56 +02:00
ba13e26ff7 fixed insights
All checks were successful
Vercel Production Deployment / Deploy-Production (push) Successful in 1m49s
2024-05-13 10:42:20 +02:00
80b079c8e5 Merge pull request 'added speed insights' (#1) from test-cicd into main
All checks were successful
Vercel Production Deployment / Deploy-Production (push) Successful in 1m57s
Reviewed-on: #1
2024-05-13 08:39:32 +00:00
46 changed files with 5043 additions and 1668 deletions

View File

@ -1,14 +0,0 @@
# Since the ".env" file is gitignored, you can use the ".env.example" file to
# build a new ".env" file when you clone the repo. Keep this file up-to-date
# when you add new variables to `.env`.
# This file will be committed to version control, so make sure not to have any
# secrets in it. If you are cloning this repo, create a copy of this file named
# ".env" and populate it with your secrets.
# When adding additional environment variables, the schema in "/src/env.js"
# should be updated accordingly.
# Prisma
# https://www.prisma.io/docs/reference/database-reference/connection-urls#env
DATABASE_URL="mysql://root:password@localhost:3306/titles"

View File

@ -1,14 +0,0 @@
# When adding additional environment variables, the schema in "/src/env.js"
# should be updated accordingly.
# Prisma
# https://www.prisma.io/docs/reference/database-reference/connection-urls#env
DATABASE_URL="postgres://default:Tb20mPEZGVUq@ep-square-cell-a29y5dq9.eu-central-1.aws.neon.tech:5432/verceldb?sslmode=require"
POSTGRES_URL="postgres://default:Tb20mPEZGVUq@ep-square-cell-a29y5dq9-pooler.eu-central-1.aws.neon.tech:5432/verceldb?sslmode=require"
POSTGRES_PRISMA_URL="postgres://default:Tb20mPEZGVUq@ep-square-cell-a29y5dq9-pooler.eu-central-1.aws.neon.tech:5432/verceldb?sslmode=require&pgbouncer=true&connect_timeout=15"
POSTGRES_URL_NO_SSL="postgres://default:Tb20mPEZGVUq@ep-square-cell-a29y5dq9-pooler.eu-central-1.aws.neon.tech:5432/verceldb"
POSTGRES_URL_NON_POOLING="postgres://default:Tb20mPEZGVUq@ep-square-cell-a29y5dq9.eu-central-1.aws.neon.tech:5432/verceldb?sslmode=require"
POSTGRES_USER="default"
POSTGRES_HOST="ep-square-cell-a29y5dq9-pooler.eu-central-1.aws.neon.tech"
POSTGRES_PASSWORD="Tb20mPEZGVUq"
POSTGRES_DATABASE="verceldb"

View File

@ -1,42 +0,0 @@
/** @type {import("eslint").Linter.Config} */
const config = {
"parser": "@typescript-eslint/parser",
"parserOptions": {
"project": true
},
"plugins": [
"@typescript-eslint"
],
"extends": [
"next/core-web-vitals",
"plugin:@typescript-eslint/recommended-type-checked",
"plugin:@typescript-eslint/stylistic-type-checked"
],
"rules": {
"@typescript-eslint/array-type": "off",
"@typescript-eslint/consistent-type-definitions": "off",
"@typescript-eslint/consistent-type-imports": [
"warn",
{
"prefer": "type-imports",
"fixStyle": "inline-type-imports"
}
],
"@typescript-eslint/no-unused-vars": [
"warn",
{
"argsIgnorePattern": "^_"
}
],
"@typescript-eslint/require-await": "off",
"@typescript-eslint/no-misused-promises": [
"error",
{
"checksVoidReturn": {
"attributes": false
}
}
]
}
}
module.exports = config;

3
.eslintrc.json Normal file
View File

@ -0,0 +1,3 @@
{
"extends": "next/core-web-vitals"
}

11
.gitignore vendored
View File

@ -4,19 +4,14 @@
/node_modules /node_modules
/.pnp /.pnp
.pnp.js .pnp.js
.yarn/install-state.gz
# testing # testing
/coverage /coverage
# database
/prisma/db.sqlite
/prisma/db.sqlite-journal
db.sqlite
# next.js # next.js
/.next/ /.next/
/out/ /out/
next-env.d.ts
# production # production
/build /build
@ -29,11 +24,8 @@ next-env.d.ts
npm-debug.log* npm-debug.log*
yarn-debug.log* yarn-debug.log*
yarn-error.log* yarn-error.log*
.pnpm-debug.log*
# local env files # local env files
# do not commit any .env files to git, except for the .env.example file. https://create.t3.gg/en/usage/env-variables#using-environment-variables
.env
.env*.local .env*.local
# vercel # vercel
@ -41,5 +33,6 @@ yarn-error.log*
# typescript # typescript
*.tsbuildinfo *.tsbuildinfo
next-env.d.ts
.vercel .vercel

View File

@ -1,29 +1,15 @@
# Create T3 App This project is scaffolded with the following:
This is a [T3 Stack](https://create.t3.gg/) project bootstrapped with `create-t3-app`. - Next.js
- Auth.js (nextauth)
- Nextui
- Next-themes
- Tailwind
- Drizzle
- Postgres
## What's next? How do I make an app with this? It is deployed to vercel and can be viewed on the following links:
We try to keep this project as simple as possible, so you can start with just the scaffolding we set up for you, and add additional things later when they become necessary. [Preview branches](https://titles-chrqr-christian-rannes-projects.vercel.app/)
If you are not familiar with the different technologies used in this project, please refer to the respective docs. If you still are in the wind, please join our [Discord](https://t3.gg/discord) and ask for help. [Production](https://titles-psi.vercel.app/)
- [Next.js](https://nextjs.org)
- [NextAuth.js](https://next-auth.js.org)
- [Prisma](https://prisma.io)
- [Drizzle](https://orm.drizzle.team)
- [Tailwind CSS](https://tailwindcss.com)
- [tRPC](https://trpc.io)
## Learn More
To learn more about the [T3 Stack](https://create.t3.gg/), take a look at the following resources:
- [Documentation](https://create.t3.gg/)
- [Learn the T3 Stack](https://create.t3.gg/en/faq#what-learning-resources-are-currently-available) — Check out these awesome tutorials
You can check out the [create-t3-app GitHub repository](https://github.com/t3-oss/create-t3-app) — your feedback and contributions are welcome!
## How do I deploy this?
Follow our deployment guides for [Vercel](https://create.t3.gg/en/deployment/vercel), [Netlify](https://create.t3.gg/en/deployment/netlify) and [Docker](https://create.t3.gg/en/deployment/docker) for more information.

View File

@ -0,0 +1,3 @@
import { handlers } from "@/auth" // Referring to the auth.ts we just created
export const { GET, POST } = handlers

BIN
app/favicon.ico Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 25 KiB

25
app/layout.tsx Normal file
View File

@ -0,0 +1,25 @@
import type { Metadata } from "next";
import { Inter } from "next/font/google";
import "./globals.css";
import { Providers } from "./providers";
const inter = Inter({ subsets: ["latin"] });
export const metadata: Metadata = {
title: "Create Next App",
description: "Generated by create next app",
};
export default function RootLayout({
children,
}: Readonly<{
children: React.ReactNode;
}>) {
return (
<html lang="en">
<body className={inter.className}>
<Providers>{children}</Providers>
</body>
</html>
);
}

18
app/page.tsx Normal file
View File

@ -0,0 +1,18 @@
import { getUsers } from "@/drizzle/db";
import SignIn from "@/components/SignIn";
import { auth } from "@/auth";
import { Session } from "next-auth";
import { ThemeSwitcher } from "@/components/ThemeSwitcher";
export default async function Home() {
const users = await getUsers();
const session: Session | null = await auth();
return (
<main className="min-h-screen w-full">
<div className="min-h-screen w-full flex flex-col items-center justify-center">
<SignIn session={session} />
<ThemeSwitcher />
</div>
</main>
);
}

14
app/providers.tsx Normal file
View File

@ -0,0 +1,14 @@
"use client";
import { NextUIProvider } from "@nextui-org/react";
import { ThemeProvider as NextThemesProvider } from "next-themes";
export function Providers({ children }: { children: React.ReactNode }) {
return (
<NextUIProvider>
<NextThemesProvider attribute="class" defaultTheme="dark">
{children}
</NextThemesProvider>
</NextUIProvider>
);
}

6
auth.ts Normal file
View File

@ -0,0 +1,6 @@
import NextAuth from "next-auth"
import GitHub from "next-auth/providers/github"
export const { handlers, signIn, signOut, auth } = NextAuth({
providers: [GitHub],
})

48
components/SignIn.tsx Normal file
View File

@ -0,0 +1,48 @@
"use client";
import { signIn, signOut } from "next-auth/react";
import { SyntheticEvent, useState } from "react";
import { Session } from "next-auth";
import { Button } from "@nextui-org/button";
import { Spinner } from "@nextui-org/react";
interface SignInProps {
session: Session | null;
}
export default function SignIn({ session }: SignInProps) {
const [loading, setLoading] = useState(false);
const handleSignIn = async (event: SyntheticEvent) => {
event.preventDefault();
setLoading(true);
await signIn("github");
};
const handleSignOut = async (event: SyntheticEvent) => {
event.preventDefault();
setLoading(true);
await signOut();
};
return (
<>
{session?.user ? (
<form onSubmit={handleSignOut}>
<Button type="submit" disabled={loading}>
Sign out
</Button>
</form>
) : (
<form onSubmit={handleSignIn}>
{!loading ? (
<Button type="submit" disabled={loading}>
Sign in
</Button>
) : (
<Spinner color="success" />
)}
</form>
)}
</>
);
}

View File

@ -0,0 +1,25 @@
// app/components/ThemeSwitcher.tsx
"use client";
import { Button } from "@nextui-org/button";
import { useTheme } from "next-themes";
import { useEffect, useState } from "react";
export function ThemeSwitcher() {
const [mounted, setMounted] = useState(false);
const { theme, setTheme } = useTheme();
useEffect(() => {
setMounted(true);
}, []);
if (!mounted) return null;
return (
<div className="flex gap-2 items-center my-2">
The current theme is: {theme}
<Button onClick={() => setTheme("light")}>Light Mode</Button>
<Button onClick={() => setTheme("dark")}>Dark Mode</Button>
</div>
);
}

10
drizzle.config.ts Normal file
View File

@ -0,0 +1,10 @@
import "@/drizzle/envConfig";
import { defineConfig } from "drizzle-kit";
export default defineConfig({
schema: "./drizzle/schema.ts",
dialect: "postgresql",
dbCredentials: {
url: process.env.POSTGRES_URL!,
},
});

10
drizzle/db.ts Normal file
View File

@ -0,0 +1,10 @@
import "@/drizzle/envConfig";
import { drizzle } from "drizzle-orm/vercel-postgres";
import { sql } from "@vercel/postgres";
import * as schema from "./schema";
export const db = drizzle(sql, { schema });
export const getUsers = async () => {
return db.query.UsersTable.findMany();
};

4
drizzle/envConfig.ts Normal file
View File

@ -0,0 +1,4 @@
import { loadEnvConfig } from "@next/env";
const projectDir = process.cwd();
loadEnvConfig(projectDir);

28
drizzle/schema.ts Normal file
View File

@ -0,0 +1,28 @@
import { drizzle } from "drizzle-orm/vercel-postgres";
import { sql } from "@vercel/postgres";
import {
pgTable,
serial,
text,
timestamp,
uniqueIndex,
} from "drizzle-orm/pg-core";
import { InferSelectModel } from "drizzle-orm";
export const UsersTable = pgTable(
"users",
{
id: serial("id").primaryKey(),
name: text("name").notNull(),
email: text("email").notNull(),
image: text("image").notNull(),
createdAt: timestamp("createdAt").defaultNow().notNull(),
},
(users) => {
return {
uniqueIdx: uniqueIndex("unique_idx").on(users.email),
};
}
);
export type Users = InferSelectModel<typeof UsersTable>;

1
middleware.ts Normal file
View File

@ -0,0 +1 @@
export { auth as middleware } from "@/auth"

View File

@ -1,10 +0,0 @@
/**
* Run `build` or `dev` with `SKIP_ENV_VALIDATION` to skip env validation. This is especially useful
* for Docker builds.
*/
await import("./src/env.js");
/** @type {import("next").NextConfig} */
const config = {};
export default config;

4
next.config.mjs Normal file
View File

@ -0,0 +1,4 @@
/** @type {import('next').NextConfig} */
const nextConfig = {};
export default nextConfig;

5692
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -2,50 +2,37 @@
"name": "titles", "name": "titles",
"version": "0.1.0", "version": "0.1.0",
"private": true, "private": true,
"type": "module",
"scripts": { "scripts": {
"build": "next build",
"db:push": "prisma db push",
"db:studio": "prisma studio",
"dev": "next dev", "dev": "next dev",
"postinstall": "prisma generate", "build": "next build",
"lint": "next lint", "start": "next start",
"start": "next start" "lint": "next lint"
}, },
"dependencies": { "dependencies": {
"@prisma/client": "^5.10.2", "@next/env": "^14.2.3",
"@t3-oss/env-nextjs": "^0.10.1", "@nextui-org/button": "^2.0.31",
"@tanstack/react-query": "^5.25.0", "@nextui-org/react": "^2.3.6",
"@trpc/client": "next", "@nextui-org/system": "^2.1.2",
"@trpc/react-query": "next", "@nextui-org/theme": "^2.2.3",
"@trpc/server": "next", "@types/next-auth": "^3.15.0",
"@vercel/speed-insights": "^1.0.10", "@vercel/postgres": "^0.8.0",
"geist": "^1.3.0", "drizzle-orm": "^0.30.10",
"next": "^14.2.1", "framer-motion": "^11.2.4",
"react": "18.2.0", "next": "14.2.3",
"react-dom": "18.2.0", "next-auth": "^5.0.0-beta.18",
"server-only": "^0.0.1", "next-themes": "^0.3.0",
"superjson": "^2.2.1", "react": "^18.3.1",
"zod": "^3.23.3" "react-dom": "^18.3.1"
}, },
"devDependencies": { "devDependencies": {
"@types/eslint": "^8.56.2", "@types/node": "^20.12.12",
"@types/node": "^20.11.20", "@types/react": "^18.3.2",
"@types/react": "^18.2.57", "@types/react-dom": "^18.3.0",
"@types/react-dom": "^18.2.19", "drizzle-kit": "^0.21.2",
"@typescript-eslint/eslint-plugin": "^7.1.1",
"@typescript-eslint/parser": "^7.1.1",
"eslint": "^8.57.0", "eslint": "^8.57.0",
"eslint-config-next": "^14.1.3", "eslint-config-next": "14.2.3",
"postcss": "^8.4.34", "postcss": "^8.4.38",
"prettier": "^3.2.5", "tailwindcss": "^3.4.3",
"prettier-plugin-tailwindcss": "^0.5.11", "typescript": "^5.4.5"
"prisma": "^5.10.2", }
"tailwindcss": "^3.4.1",
"typescript": "^5.4.2"
},
"ct3aMetadata": {
"initVersion": "7.33.1"
},
"packageManager": "npm@10.2.4"
} }

View File

@ -1,7 +0,0 @@
const config = {
plugins: {
tailwindcss: {},
},
};
module.exports = config;

8
postcss.config.mjs Normal file
View File

@ -0,0 +1,8 @@
/** @type {import('postcss-load-config').Config} */
const config = {
plugins: {
tailwindcss: {},
},
};
export default config;

View File

@ -1,6 +0,0 @@
/** @type {import('prettier').Config & import('prettier-plugin-tailwindcss').PluginOptions} */
const config = {
plugins: ["prettier-plugin-tailwindcss"],
};
export default config;

View File

@ -1,22 +0,0 @@
// This is your Prisma schema file,
// learn more about it in the docs: https://pris.ly/d/prisma-schema
generator client {
provider = "prisma-client-js"
binaryTargets = "rhel-openssl-3.0.x"
}
datasource db {
provider = "postgresql"
url = env("POSTGRES_PRISMA_URL") // uses connection pooling
directUrl = env("POSTGRES_URL_NON_POOLING") // uses a direct connection
}
model Post {
id Int @id @default(autoincrement())
name String
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
@@index([name])
}

Binary file not shown.

Before

Width:  |  Height:  |  Size: 15 KiB

BIN
public/leverpostej.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 338 KiB

1
public/next.svg Normal file
View File

@ -0,0 +1 @@
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 394 80"><path fill="#000" d="M262 0h68.5v12.7h-27.2v66.6h-13.6V12.7H262V0ZM149 0v12.7H94v20.4h44.3v12.6H94v21h55v12.6H80.5V0h68.7zm34.3 0h-17.8l63.8 79.4h17.9l-32-39.7 32-39.6h-17.9l-23 28.6-23-28.6zm18.3 56.7-9-11-27.1 33.7h17.8l18.3-22.7z"/><path fill="#000" d="M81 79.3 17 0H0v79.3h13.6V17l50.2 62.3H81Zm252.6-.4c-1 0-1.8-.4-2.5-1s-1.1-1.6-1.1-2.6.3-1.8 1-2.5 1.6-1 2.6-1 1.8.3 2.5 1a3.4 3.4 0 0 1 .6 4.3 3.7 3.7 0 0 1-3 1.8zm23.2-33.5h6v23.3c0 2.1-.4 4-1.3 5.5a9.1 9.1 0 0 1-3.8 3.5c-1.6.8-3.5 1.3-5.7 1.3-2 0-3.7-.4-5.3-1s-2.8-1.8-3.7-3.2c-.9-1.3-1.4-3-1.4-5h6c.1.8.3 1.6.7 2.2s1 1.2 1.6 1.5c.7.4 1.5.5 2.4.5 1 0 1.8-.2 2.4-.6a4 4 0 0 0 1.6-1.8c.3-.8.5-1.8.5-3V45.5zm30.9 9.1a4.4 4.4 0 0 0-2-3.3 7.5 7.5 0 0 0-4.3-1.1c-1.3 0-2.4.2-3.3.5-.9.4-1.6 1-2 1.6a3.5 3.5 0 0 0-.3 4c.3.5.7.9 1.3 1.2l1.8 1 2 .5 3.2.8c1.3.3 2.5.7 3.7 1.2a13 13 0 0 1 3.2 1.8 8.1 8.1 0 0 1 3 6.5c0 2-.5 3.7-1.5 5.1a10 10 0 0 1-4.4 3.5c-1.8.8-4.1 1.2-6.8 1.2-2.6 0-4.9-.4-6.8-1.2-2-.8-3.4-2-4.5-3.5a10 10 0 0 1-1.7-5.6h6a5 5 0 0 0 3.5 4.6c1 .4 2.2.6 3.4.6 1.3 0 2.5-.2 3.5-.6 1-.4 1.8-1 2.4-1.7a4 4 0 0 0 .8-2.4c0-.9-.2-1.6-.7-2.2a11 11 0 0 0-2.1-1.4l-3.2-1-3.8-1c-2.8-.7-5-1.7-6.6-3.2a7.2 7.2 0 0 1-2.4-5.7 8 8 0 0 1 1.7-5 10 10 0 0 1 4.3-3.5c2-.8 4-1.2 6.4-1.2 2.3 0 4.4.4 6.2 1.2 1.8.8 3.2 2 4.3 3.4 1 1.4 1.5 3 1.5 5h-5.8z"/></svg>

After

Width:  |  Height:  |  Size: 1.3 KiB

1
public/vercel.svg Normal file
View File

@ -0,0 +1 @@
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 283 64"><path fill="black" d="M141 16c-11 0-19 7-19 18s9 18 20 18c7 0 13-3 16-7l-7-5c-2 3-6 4-9 4-5 0-9-3-10-7h28v-3c0-11-8-18-19-18zm-9 15c1-4 4-7 9-7s8 3 9 7h-18zm117-15c-11 0-19 7-19 18s9 18 20 18c6 0 12-3 16-7l-8-5c-2 3-5 4-8 4-5 0-9-3-11-7h28l1-3c0-11-8-18-19-18zm-10 15c2-4 5-7 10-7s8 3 9 7h-19zm-39 3c0 6 4 10 10 10 4 0 7-2 9-5l8 5c-3 5-9 8-17 8-11 0-19-7-19-18s8-18 19-18c8 0 14 3 17 8l-8 5c-2-3-5-5-9-5-6 0-10 4-10 10zm83-29v46h-9V5h9zM37 0l37 64H0L37 0zm92 5-27 48L74 5h10l18 30 17-30h10zm59 12v10l-3-1c-6 0-10 4-10 10v15h-9V17h9v9c0-5 6-9 13-9z"/></svg>

After

Width:  |  Height:  |  Size: 629 B

View File

@ -1,43 +0,0 @@
"use client";
import { useRouter } from "next/navigation";
import { useState } from "react";
import { api } from "~/trpc/react";
export function CreatePost() {
const router = useRouter();
const [name, setName] = useState("");
const createPost = api.post.create.useMutation({
onSuccess: () => {
router.refresh();
setName("");
},
});
return (
<form
onSubmit={(e) => {
e.preventDefault();
createPost.mutate({ name });
}}
className="flex flex-col gap-2"
>
<input
type="text"
placeholder="Title"
value={name}
onChange={(e) => setName(e.target.value)}
className="w-full rounded-full px-4 py-2 text-black"
/>
<button
type="submit"
className="rounded-full bg-white/10 px-10 py-3 font-semibold transition hover:bg-white/20"
disabled={createPost.isPending}
>
{createPost.isPending ? "Submitting..." : "Submit"}
</button>
</form>
);
}

View File

@ -1,34 +0,0 @@
import { fetchRequestHandler } from "@trpc/server/adapters/fetch";
import { type NextRequest } from "next/server";
import { env } from "~/env";
import { appRouter } from "~/server/api/root";
import { createTRPCContext } from "~/server/api/trpc";
/**
* This wraps the `createTRPCContext` helper and provides the required context for the tRPC API when
* handling a HTTP request (e.g. when you make requests from Client Components).
*/
const createContext = async (req: NextRequest) => {
return createTRPCContext({
headers: req.headers,
});
};
const handler = (req: NextRequest) =>
fetchRequestHandler({
endpoint: "/api/trpc",
req,
router: appRouter,
createContext: () => createContext(req),
onError:
env.NODE_ENV === "development"
? ({ path, error }) => {
console.error(
`❌ tRPC failed on ${path ?? "<no-path>"}: ${error.message}`
);
}
: undefined,
});
export { handler as GET, handler as POST };

View File

@ -1,25 +0,0 @@
import "~/styles/globals.css";
import { SpeedInsights } from "@vercel/speed-insights/next";
import { GeistSans } from "geist/font/sans";
import { TRPCReactProvider } from "~/trpc/react";
export const metadata = {
title: "Create T3 App",
description: "Generated by create-t3-app",
icons: [{ rel: "icon", url: "/favicon.ico" }],
};
export default function RootLayout({
children,
}: {
children: React.ReactNode;
}) {
return (
<html lang="en" className={`${GeistSans.variable}`}>
<body>
<TRPCReactProvider>{children}</TRPCReactProvider>
</body>
</html>
);
}

View File

@ -1,65 +0,0 @@
import Link from "next/link";
import { CreatePost } from "~/app/_components/create-post";
import { api } from "~/trpc/server";
export default async function Home() {
const hello = await api.post.hello({ text: "from tRPC" });
return (
<main className="flex min-h-screen flex-col items-center justify-center bg-gradient-to-b from-[#2e026d] to-[#15162c] text-white">
<div className="container flex flex-col items-center justify-center gap-12 px-4 py-16 ">
<h1 className="text-5xl font-extrabold tracking-tight sm:text-[5rem]">
Create <span className="text-[hsl(280,100%,70%)]">T3</span> App
</h1>
<div className="grid grid-cols-1 gap-4 sm:grid-cols-2 md:gap-8">
<Link
className="flex max-w-xs flex-col gap-4 rounded-xl bg-white/10 p-4 hover:bg-white/20"
href="https://create.t3.gg/en/usage/first-steps"
target="_blank"
>
<h3 className="text-2xl font-bold">First Steps </h3>
<div className="text-lg">
Just the basics - Everything you need to know to set up your
database and authentication.
</div>
</Link>
<Link
className="flex max-w-xs flex-col gap-4 rounded-xl bg-white/10 p-4 hover:bg-white/20"
href="https://create.t3.gg/en/introduction"
target="_blank"
>
<h3 className="text-2xl font-bold">Documentation </h3>
<div className="text-lg">
Learn more about Create T3 App, the libraries it uses, and how to
deploy it.
</div>
</Link>
</div>
<div className="flex flex-col items-center gap-2">
<p className="text-2xl text-white">
{hello ? hello.greeting : "Loading tRPC query..."}
</p>
</div>
<CrudShowcase />
</div>
</main>
);
}
async function CrudShowcase() {
const latestPost = await api.post.getLatest();
return (
<div className="w-full max-w-xs">
{latestPost ? (
<p className="truncate">Your most recent post: {latestPost.name}</p>
) : (
<p>You have no posts yet.</p>
)}
<CreatePost />
</div>
);
}

View File

@ -1,44 +0,0 @@
import { createEnv } from "@t3-oss/env-nextjs";
import { z } from "zod";
export const env = createEnv({
/**
* Specify your server-side environment variables schema here. This way you can ensure the app
* isn't built with invalid env vars.
*/
server: {
DATABASE_URL: z.string().url(),
NODE_ENV: z
.enum(["development", "test", "production"])
.default("development"),
},
/**
* Specify your client-side environment variables schema here. This way you can ensure the app
* isn't built with invalid env vars. To expose them to the client, prefix them with
* `NEXT_PUBLIC_`.
*/
client: {
// NEXT_PUBLIC_CLIENTVAR: z.string(),
},
/**
* You can't destruct `process.env` as a regular object in the Next.js edge runtimes (e.g.
* middlewares) or client-side so we need to destruct manually.
*/
runtimeEnv: {
DATABASE_URL: process.env.DATABASE_URL,
NODE_ENV: process.env.NODE_ENV,
// NEXT_PUBLIC_CLIENTVAR: process.env.NEXT_PUBLIC_CLIENTVAR,
},
/**
* Run `build` or `dev` with `SKIP_ENV_VALIDATION` to skip env validation. This is especially
* useful for Docker builds.
*/
skipValidation: !!process.env.SKIP_ENV_VALIDATION,
/**
* Makes it so that empty strings are treated as undefined. `SOME_VAR: z.string()` and
* `SOME_VAR=''` will throw an error.
*/
emptyStringAsUndefined: true,
});

View File

@ -1,23 +0,0 @@
import { postRouter } from "~/server/api/routers/post";
import { createCallerFactory, createTRPCRouter } from "~/server/api/trpc";
/**
* This is the primary router for your server.
*
* All routers added in /api/routers should be manually added here.
*/
export const appRouter = createTRPCRouter({
post: postRouter,
});
// export type definition of API
export type AppRouter = typeof appRouter;
/**
* Create a server-side caller for the tRPC API.
* @example
* const trpc = createCaller(createContext);
* const res = await trpc.post.all();
* ^? Post[]
*/
export const createCaller = createCallerFactory(appRouter);

View File

@ -1,32 +0,0 @@
import { z } from "zod";
import { createTRPCRouter, publicProcedure } from "~/server/api/trpc";
export const postRouter = createTRPCRouter({
hello: publicProcedure
.input(z.object({ text: z.string() }))
.query(({ input }) => {
return {
greeting: `Hello ${input.text}`,
};
}),
create: publicProcedure
.input(z.object({ name: z.string().min(1) }))
.mutation(async ({ ctx, input }) => {
// simulate a slow db call
await new Promise((resolve) => setTimeout(resolve, 1000));
return ctx.db.post.create({
data: {
name: input.name,
},
});
}),
getLatest: publicProcedure.query(({ ctx }) => {
return ctx.db.post.findFirst({
orderBy: { createdAt: "desc" },
});
}),
});

View File

@ -1,83 +0,0 @@
/**
* YOU PROBABLY DON'T NEED TO EDIT THIS FILE, UNLESS:
* 1. You want to modify request context (see Part 1).
* 2. You want to create a new middleware or type of procedure (see Part 3).
*
* TL;DR - This is where all the tRPC server stuff is created and plugged in. The pieces you will
* need to use are documented accordingly near the end.
*/
import { initTRPC } from "@trpc/server";
import superjson from "superjson";
import { ZodError } from "zod";
import { db } from "~/server/db";
/**
* 1. CONTEXT
*
* This section defines the "contexts" that are available in the backend API.
*
* These allow you to access things when processing a request, like the database, the session, etc.
*
* This helper generates the "internals" for a tRPC context. The API handler and RSC clients each
* wrap this and provides the required context.
*
* @see https://trpc.io/docs/server/context
*/
export const createTRPCContext = async (opts: { headers: Headers }) => {
return {
db,
...opts,
};
};
/**
* 2. INITIALIZATION
*
* This is where the tRPC API is initialized, connecting the context and transformer. We also parse
* ZodErrors so that you get typesafety on the frontend if your procedure fails due to validation
* errors on the backend.
*/
const t = initTRPC.context<typeof createTRPCContext>().create({
transformer: superjson,
errorFormatter({ shape, error }) {
return {
...shape,
data: {
...shape.data,
zodError:
error.cause instanceof ZodError ? error.cause.flatten() : null,
},
};
},
});
/**
* Create a server-side caller.
*
* @see https://trpc.io/docs/server/server-side-calls
*/
export const createCallerFactory = t.createCallerFactory;
/**
* 3. ROUTER & PROCEDURE (THE IMPORTANT BIT)
*
* These are the pieces you use to build your tRPC API. You should import these a lot in the
* "/src/server/api/routers" directory.
*/
/**
* This is how you create new routers and sub-routers in your tRPC API.
*
* @see https://trpc.io/docs/router
*/
export const createTRPCRouter = t.router;
/**
* Public (unauthenticated) procedure
*
* This is the base piece you use to build new queries and mutations on your tRPC API. It does not
* guarantee that a user querying is authorized, but you can still access user session data if they
* are logged in.
*/
export const publicProcedure = t.procedure;

View File

@ -1,17 +0,0 @@
import { PrismaClient } from "@prisma/client";
import { env } from "~/env";
const createPrismaClient = () =>
new PrismaClient({
log:
env.NODE_ENV === "development" ? ["query", "error", "warn"] : ["error"],
});
const globalForPrisma = globalThis as unknown as {
prisma: ReturnType<typeof createPrismaClient> | undefined;
};
export const db = globalForPrisma.prisma ?? createPrismaClient();
if (env.NODE_ENV !== "production") globalForPrisma.prisma = db;

View File

@ -1,77 +0,0 @@
"use client";
import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
import { loggerLink, unstable_httpBatchStreamLink } from "@trpc/client";
import { createTRPCReact } from "@trpc/react-query";
import { type inferRouterInputs, type inferRouterOutputs } from "@trpc/server";
import { useState } from "react";
import SuperJSON from "superjson";
import { type AppRouter } from "~/server/api/root";
const createQueryClient = () => new QueryClient();
let clientQueryClientSingleton: QueryClient | undefined = undefined;
const getQueryClient = () => {
if (typeof window === "undefined") {
// Server: always make a new query client
return createQueryClient();
}
// Browser: use singleton pattern to keep the same query client
return (clientQueryClientSingleton ??= createQueryClient());
};
export const api = createTRPCReact<AppRouter>();
/**
* Inference helper for inputs.
*
* @example type HelloInput = RouterInputs['example']['hello']
*/
export type RouterInputs = inferRouterInputs<AppRouter>;
/**
* Inference helper for outputs.
*
* @example type HelloOutput = RouterOutputs['example']['hello']
*/
export type RouterOutputs = inferRouterOutputs<AppRouter>;
export function TRPCReactProvider(props: { children: React.ReactNode }) {
const queryClient = getQueryClient();
const [trpcClient] = useState(() =>
api.createClient({
links: [
loggerLink({
enabled: (op) =>
process.env.NODE_ENV === "development" ||
(op.direction === "down" && op.result instanceof Error),
}),
unstable_httpBatchStreamLink({
transformer: SuperJSON,
url: getBaseUrl() + "/api/trpc",
headers: () => {
const headers = new Headers();
headers.set("x-trpc-source", "nextjs-react");
return headers;
},
}),
],
})
);
return (
<QueryClientProvider client={queryClient}>
<api.Provider client={trpcClient} queryClient={queryClient}>
{props.children}
</api.Provider>
</QueryClientProvider>
);
}
function getBaseUrl() {
if (typeof window !== "undefined") return window.location.origin;
if (process.env.VERCEL_URL) return `https://${process.env.VERCEL_URL}`;
return `http://localhost:${process.env.PORT ?? 3000}`;
}

View File

@ -1,22 +0,0 @@
import "server-only";
import { headers } from "next/headers";
import { cache } from "react";
import { createCaller } from "~/server/api/root";
import { createTRPCContext } from "~/server/api/trpc";
/**
* This wraps the `createTRPCContext` helper and provides the required context for the tRPC API when
* handling a tRPC call from a React Server Component.
*/
const createContext = cache(() => {
const heads = new Headers(headers());
heads.set("x-trpc-source", "rsc");
return createTRPCContext({
headers: heads,
});
});
export const api = createCaller(createContext);

View File

@ -1,54 +0,0 @@
#!/usr/bin/env bash
# Use this script to start a docker container for a local development database
# TO RUN ON WINDOWS:
# 1. Install WSL (Windows Subsystem for Linux) - https://learn.microsoft.com/en-us/windows/wsl/install
# 2. Install Docker Desktop for Windows - https://docs.docker.com/docker-for-windows/install/
# 3. Open WSL - `wsl`
# 4. Run this script - `./start-database.sh`
# On Linux and macOS you can run this script directly - `./start-database.sh`
DB_CONTAINER_NAME="titles-mysql"
if ! [ -x "$(command -v docker)" ]; then
echo -e "Docker is not installed. Please install docker and try again.\nDocker install guide: https://docs.docker.com/engine/install/"
exit 1
fi
if [ "$(docker ps -q -f name=$DB_CONTAINER_NAME)" ]; then
echo "Database container '$DB_CONTAINER_NAME' already running"
exit 0
fi
if [ "$(docker ps -q -a -f name=$DB_CONTAINER_NAME)" ]; then
docker start "$DB_CONTAINER_NAME"
echo "Existing database container '$DB_CONTAINER_NAME' started"
exit 0
fi
# import env variables from .env
set -a
source .env
DB_PASSWORD=$(echo "$DATABASE_URL" | awk -F':' '{print $3}' | awk -F'@' '{print $1}')
DB_PORT=$(echo "$DATABASE_URL" | awk -F':' '{print $4}' | awk -F'\/' '{print $1}')
if [ "$DB_PASSWORD" == "password" ]; then
echo "You are using the default database password"
read -p "Should we generate a random password for you? [y/N]: " -r REPLY
if ! [[ $REPLY =~ ^[Yy]$ ]]; then
echo "Please set a password in the .env file and try again"
exit 1
fi
# Generate a random URL-safe password
DB_PASSWORD=$(openssl rand -base64 12 | tr '+/' '-_')
sed -i -e "s#:password@#:$DB_PASSWORD@#" .env
fi
docker run -d \
--name $DB_CONTAINER_NAME \
-e MYSQL_ROOT_PASSWORD="$DB_PASSWORD" \
-e MYSQL_DATABASE=titles \
-p "$DB_PORT":3306 \
docker.io/mysql && echo "Database container '$DB_CONTAINER_NAME' was successfully created"

View File

@ -1,14 +1,18 @@
import { type Config } from "tailwindcss"; import { nextui } from "@nextui-org/theme";
import { fontFamily } from "tailwindcss/defaultTheme"; import type { Config } from "tailwindcss";
export default { const config: Config = {
content: ["./src/**/*.tsx"], content: [
"./pages/**/*.{js,ts,jsx,tsx,mdx}",
"./components/**/*.{js,ts,jsx,tsx,mdx}",
"./app/**/*.{js,ts,jsx,tsx,mdx}",
"./node_modules/@nextui-org/theme/dist/components/(button|ripple|spinner).js",
"./node_modules/@nextui-org/theme/dist/**/*.{js,ts,jsx,tsx}",
],
theme: { theme: {
extend: { extend: {},
fontFamily: {
sans: ["var(--font-geist-sans)", ...fontFamily.sans],
}, },
}, darkMode: "class",
}, plugins: [nextui()],
plugins: [], };
} satisfies Config; export default config;

View File

@ -1,42 +1,32 @@
{ {
"compilerOptions": { "compilerOptions": {
/* Base Options: */ "lib": ["dom", "dom.iterable", "esnext"],
"esModuleInterop": true,
"skipLibCheck": true,
"target": "es2022",
"allowJs": true, "allowJs": true,
"resolveJsonModule": true, "skipLibCheck": true,
"moduleDetection": "force",
"isolatedModules": true,
/* Strictness */
"strict": true, "strict": true,
"noUncheckedIndexedAccess": true,
"checkJs": true,
/* Bundled projects */
"lib": ["dom", "dom.iterable", "ES2022"],
"noEmit": true, "noEmit": true,
"module": "ESNext", "esModuleInterop": true,
"moduleResolution": "Bundler", "module": "esnext",
"moduleResolution": "bundler",
"resolveJsonModule": true,
"isolatedModules": true,
"jsx": "preserve", "jsx": "preserve",
"plugins": [{ "name": "next" }],
"incremental": true, "incremental": true,
"plugins": [
/* Path Aliases */ {
"baseUrl": ".", "name": "next"
}
],
"paths": { "paths": {
"~/*": ["./src/*"] "@/*": ["./*"]
} }
}, },
"include": [ "include": [
".eslintrc.cjs",
"next-env.d.ts", "next-env.d.ts",
"**/*.ts", "**/*.ts",
"**/*.tsx", "**/*.tsx",
"**/*.cjs", ".next/types/**/*.ts",
"**/*.js", "drizzle.config.ts"
".next/types/**/*.ts"
], ],
"exclude": ["node_modules"] "exclude": ["node_modules"]
} }