diff --git a/.env.example b/.env.example new file mode 100644 index 0000000..3381199 --- /dev/null +++ b/.env.example @@ -0,0 +1,18 @@ +# Since .env is gitignored, you can use .env.example 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. + +# The database URL is used to connect to your Turso database. +DB_URL='aws.connect.psdb.cloud' +DB_AUTH_TOKEN='YOUR_DB_NAME' + +# You can generate the secret via 'openssl rand -base64 32' on Unix +# @see https://next-auth.js.org/configuration/options#secret +AUTH_SECRET='supersecret' + +# Preconfigured Discord OAuth provider, works out-of-the-box +# @see https://next-auth.js.org/providers/discord +AUTH_DISCORD_ID='' +AUTH_DISCORD_SECRET='' diff --git a/.github/FUNDING.yml b/.github/FUNDING.yml new file mode 100644 index 0000000..fa0ab87 --- /dev/null +++ b/.github/FUNDING.yml @@ -0,0 +1,3 @@ +# These are supported funding model platforms + +github: maxwiseman diff --git a/.github/ISSUE_TEMPLATE/bug_report.yml b/.github/ISSUE_TEMPLATE/bug_report.yml new file mode 100644 index 0000000..54199a8 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/bug_report.yml @@ -0,0 +1,37 @@ +name: 🐞 Bug Report +description: Create a bug report to help us improve +title: "bug: " +labels: ["🐞❔ unconfirmed bug"] +body: + - type: textarea + attributes: + label: Provide environment information + description: | + Run this command in your project root and paste the results in a code block: + ```bash + npx envinfo --system --binaries + ``` + validations: + required: true + - type: textarea + attributes: + label: Describe the bug + description: A clear and concise description of the bug, as well as what you expected to happen when encountering it. + validations: + required: true + - type: input + attributes: + label: Link to reproduction + description: Please provide a link to a reproduction of the bug. Issues without a reproduction repo may be ignored. + validations: + required: true + - type: textarea + attributes: + label: To reproduce + description: Describe how to reproduce your bug. Steps, code snippets, reproduction repos etc. + validations: + required: true + - type: textarea + attributes: + label: Additional information + description: Add any other information related to the bug here, screenshots if applicable. diff --git a/.github/ISSUE_TEMPLATE/feature_request.yml b/.github/ISSUE_TEMPLATE/feature_request.yml new file mode 100644 index 0000000..44f8843 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/feature_request.yml @@ -0,0 +1,28 @@ +# This template is heavily inspired by the Next.js's template: +# See here: https://github.com/vercel/next.js/tree/canary/.github/ISSUE_TEMPLATE + +name: 🛠 Feature Request +description: Create a feature request for the core packages +title: "feat: " +labels: ["✨ enhancement"] +body: + - type: markdown + attributes: + value: | + Thank you for taking the time to file a feature request. Please fill out this form as completely as possible. + - type: textarea + attributes: + label: Describe the feature you'd like to request + description: Please describe the feature as clear and concise as possible. Remember to add context as to why you believe this feature is needed. + validations: + required: true + - type: textarea + attributes: + label: Describe the solution you'd like to see + description: Please describe the solution you would like to see. Adding example usage is a good way to provide context. + validations: + required: true + - type: textarea + attributes: + label: Additional information + description: Add any other information related to the feature here. If your feature request is related to any issues or discussions, link them here. diff --git a/.github/renovate.json b/.github/renovate.json new file mode 100644 index 0000000..232b8ea --- /dev/null +++ b/.github/renovate.json @@ -0,0 +1,13 @@ +{ + "$schema": "https://docs.renovatebot.com/renovate-schema.json", + "extends": ["config:base"], + "packageRules": [ + { + "matchPackagePatterns": ["^@quotes/"], + "enabled": false + } + ], + "updateInternalDeps": true, + "rangeStrategy": "bump", + "automerge": true +} diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..d30b271 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,57 @@ +name: CI + +on: + pull_request: + branches: ["*"] + push: + branches: ["main"] + merge_group: + +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: ${{ github.ref != 'refs/heads/main' }} + +# You can leverage Vercel Remote Caching with Turbo to speed up your builds +# @link https://turborepo.org/docs/core-concepts/remote-caching#remote-caching-on-vercel-builds +env: + FORCE_COLOR: 3 + TURBO_TEAM: ${{ vars.TURBO_TEAM }} + TURBO_TOKEN: ${{ secrets.TURBO_TOKEN }} + +jobs: + lint: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + + - name: Setup + uses: ./tooling/github/setup + + - name: Copy env + shell: bash + run: cp .env.example .env + + - name: Lint + run: bun lint && bun lint:ws + + format: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + + - name: Setup + uses: ./tooling/github/setup + + - name: Format + run: bun format + + typecheck: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + + - name: Setup + uses: ./tooling/github/setup + + - name: Typecheck + run: bun typecheck diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..1e7a76d --- /dev/null +++ b/.gitignore @@ -0,0 +1,50 @@ +# See https://help.github.com/articles/ignoring-files/ for more about ignoring files. + +# dependencies +node_modules +.pnp +.pnp.js + +# testing +coverage + +# next.js +.next/ +out/ +next-env.d.ts + +# nitro +.nitro/ +.output/ + +# expo +.expo/ +dist/ +expo-env.d.ts +apps/expo/.gitignore + +# production +build + +# misc +.DS_Store +*.pem + +# debug +npm-debug.log* +yarn-debug.log* +yarn-error.log* +.pnpm-debug.log* + +# local env files +.env +.env*.local + +# vercel +.vercel + +# typescript +*.tsbuildinfo + +# turbo +.turbo diff --git a/.npmrc b/.npmrc new file mode 100644 index 0000000..d67f374 --- /dev/null +++ b/.npmrc @@ -0,0 +1 @@ +node-linker=hoisted diff --git a/.nvmrc b/.nvmrc new file mode 100644 index 0000000..a3d2332 --- /dev/null +++ b/.nvmrc @@ -0,0 +1 @@ +20.11 \ No newline at end of file diff --git a/.vscode/extensions.json b/.vscode/extensions.json new file mode 100644 index 0000000..3606d87 --- /dev/null +++ b/.vscode/extensions.json @@ -0,0 +1,9 @@ +{ + "recommendations": [ + "dbaeumer.vscode-eslint", + "expo.vscode-expo-tools", + "esbenp.prettier-vscode", + "yoavbls.pretty-ts-errors", + "bradlc.vscode-tailwindcss" + ] +} diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 0000000..5fcd845 --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,13 @@ +{ + "version": "0.2.0", + "configurations": [ + { + "name": "Next.js", + "type": "node-terminal", + "request": "launch", + "command": "pnpm dev", + "cwd": "${workspaceFolder}/apps/nextjs/", + "skipFiles": ["/**"] + } + ] +} diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..2797d92 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,24 @@ +{ + "editor.codeActionsOnSave": { + "source.fixAll.eslint": "explicit" + }, + "editor.defaultFormatter": "esbenp.prettier-vscode", + "editor.formatOnSave": true, + "eslint.rules.customizations": [{ "rule": "*", "severity": "warn" }], + "eslint.workingDirectories": [ + { "pattern": "apps/*/" }, + { "pattern": "packages/*/" }, + { "pattern": "tooling/*/" } + ], + "tailwindCSS.experimental.classRegex": [ + ["cva\\(([^)]*)\\)", "[\"'`]([^\"'`]*).*?[\"'`]"], + ["cx\\(([^)]*)\\)", "(?:'|\"|`)([^']*)(?:'|\"|`)"] + ], + "tailwindCSS.experimental.configFile": "./tooling/tailwind/web.ts", + "typescript.enablePromptUseWorkspaceTsdk": true, + "typescript.preferences.autoImportFileExcludePatterns": [ + "next/router.d.ts", + "next/dist/client/router.d.ts" + ], + "typescript.tsdk": "node_modules/typescript/lib" +} diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..c7651ed --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2024 Max Wiseman + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/README.md b/README.md new file mode 100644 index 0000000..1ee8459 --- /dev/null +++ b/README.md @@ -0,0 +1,247 @@ +# create-t3-turbo + +> **Note** +> Due to high demand, this repo now uses the `app` directory with some new experimental features. If you want to use the more traditional `pages` router, [check out the repo before the update](https://github.com/t3-oss/create-t3-turbo/tree/414aff131ca124573e721f3779df3edb64989fd4). + +> **Note** +> OAuth deployments are now working for preview deployments. Read [deployment guide](https://github.com/t3-oss/create-t3-turbo#auth-proxy) and [check out the source](./apps/auth-proxy) to learn more! + +## Installation + +There are two ways of initializing an app using the `create-t3-turbo` starter. You can either use this repository as a template: + +![use-as-template](https://github.com/t3-oss/create-t3-turbo/assets/51714798/bb6c2e5d-d8b6-416e-aeb3-b3e50e2ca994) + +or use Turbo's CLI to init your project (use PNPM as package manager): + +```bash +npx create-turbo@latest -e https://github.com/t3-oss/create-t3-turbo +``` + +## About + +Ever wondered how to migrate your T3 application into a monorepo? Stop right here! This is the perfect starter repo to get you running with the perfect stack! + +It uses [Turborepo](https://turborepo.org) and contains: + +```text +.github + └─ workflows + └─ CI with pnpm cache setup +.vscode + └─ Recommended extensions and settings for VSCode users +apps + ├─ auth-proxy + | ├─ Nitro server to proxy OAuth requests in preview deployments + | └─ Uses Auth.js Core + ├─ expo + | ├─ Expo SDK 49 + | ├─ React Native using React 18 + | ├─ Navigation using Expo Router + | ├─ Tailwind using NativeWind + | └─ Typesafe API calls using tRPC + └─ next.js + ├─ Next.js 14 + ├─ React 18 + ├─ Tailwind CSS + └─ E2E Typesafe API Server & Client +packages + ├─ api + | └─ tRPC v11 router definition + ├─ auth + | └─ Authentication using next-auth. **NOTE: Only for Next.js app, not Expo** + ├─ db + | └─ Typesafe db calls using Drizzle & Turso + └─ ui + └─ Start of a UI package for the webapp using shadcn-ui +tooling + ├─ eslint + | └─ shared, fine-grained, eslint presets + ├─ prettier + | └─ shared prettier configuration + ├─ tailwind + | └─ shared tailwind configuration + └─ typescript + └─ shared tsconfig you can extend from +``` + +> In this template, we use `@quotes` as a placeholder for package names. As a user, you might want to replace it with your own organization or project name. You can use find-and-replace to change all the instances of `@quotes` to something like `@my-company` or `@project-name`. + +## Quick Start + +> **Note** +> The [db](./packages/db) package is preconfigured to use Turso. If you're using something else, make the necessary modifications to the [schema](./packages/db/src/schema) as well as the [client](./packages/db/src/index.ts) and the [drizzle config](./packages/db/drizzle.config.ts). If you want to switch to non-edge database driver, remove `export const runtime = "edge";` [from all pages and api routes](https://github.com/t3-oss/create-t3-turbo/issues/634#issuecomment-1730240214). + +To get it running, follow the steps below: + +### 1. Setup dependencies + +```bash +# Install dependencies +pnpm i + +# Configure environment variables +# There is an `.env.example` in the root directory you can use for reference +cp .env.example .env + +# Push the Drizzle schema to the database +pnpm db:push +``` + +### 2. Configure Expo `dev`-script + +#### Use iOS Simulator + +1. Make sure you have XCode and XCommand Line Tools installed [as shown on expo docs](https://docs.expo.dev/workflow/ios-simulator). + + > **NOTE:** If you just installed XCode, or if you have updated it, you need to open the simulator manually once. Run `npx expo start` in the root dir, and then enter `I` to launch Expo Go. After the manual launch, you can run `pnpm dev` in the root directory. + + ```diff + + "dev": "expo start --ios", + ``` + +2. Run `pnpm dev` at the project root folder. + +#### Use Android Emulator + +1. Install Android Studio tools [as shown on expo docs](https://docs.expo.dev/workflow/android-studio-emulator). + +2. Change the `dev` script at `apps/expo/package.json` to open the Android emulator. + + ```diff + + "dev": "expo start --android", + ``` + +3. Run `pnpm dev` at the project root folder. + +> **TIP:** It might be easier to run each app in separate terminal windows, so you get the logs from each app separately. This is also required if you want your terminals to be interactive, e.g. to access the Expo QR code. You can run `pnpm --filter expo dev` and `pnpm --filter nextjs dev` to run each app in a separate terminal window. + +### 3. When it's time to add a new package + +To add a new package, simply run `pnpm turbo gen init` in the monorepo root. This will prompt you for a package name as well as if you want to install any dependencies to the new package (of course you can also do this yourself later). + +The generator sets up the `package.json`, `tsconfig.json` and a `index.ts`, as well as configures all the necessary configurations for tooling around your package such as formatting, linting and typechecking. When the package is created, you're ready to go build out the package. + +## FAQ + +### Does the starter include Solito? + +No. Solito will not be included in this repo. It is a great tool if you want to share code between your Next.js and Expo app. However, the main purpose of this repo is not the integration between Next.js and Expo — it's the code splitting of your T3 App into a monorepo. The Expo app is just a bonus example of how you can utilize the monorepo with multiple apps but can just as well be any app such as Vite, Electron, etc. + +Integrating Solito into this repo isn't hard, and there are a few [official templates](https://github.com/nandorojo/solito/tree/master/example-monorepos) by the creators of Solito that you can use as a reference. + +### What auth solution should I use instead of Next-Auth.js for Expo? + +I've left this kind of open for you to decide. Some options are [Clerk](https://clerk.dev), [Supabase Auth](https://supabase.com/docs/guides/auth), [Firebase Auth](https://firebase.google.com/docs/auth/) or [Auth0](https://auth0.com/docs). Note that if you're dropping the Expo app for something more "browser-like", you can still use Next-Auth.js for those. [See an example in a Plasmo Chrome Extension here](https://github.com/t3-oss/create-t3-turbo/tree/chrome/apps/chrome). + +The Clerk.dev team even made an [official template repository](https://github.com/clerkinc/t3-turbo-and-clerk) integrating Clerk.dev with this repo. + +During Launch Week 7, Supabase [announced their fork](https://supabase.com/blog/launch-week-7-community-highlights#t3-turbo-x-supabase) of this repo integrating it with their newly announced auth improvements. You can check it out [here](https://github.com/supabase-community/create-t3-turbo). + +### Does this pattern leak backend code to my client applications? + +No, it does not. The `api` package should only be a production dependency in the Next.js application where it's served. The Expo app, and all other apps you may add in the future, should only add the `api` package as a dev dependency. This lets you have full typesafety in your client applications, while keeping your backend code safe. + +If you need to share runtime code between the client and server, such as input validation schemas, you can create a separate `shared` package for this and import it on both sides. + +## Deployment + +### Next.js + +#### Prerequisites + +> **Note** +> Please note that the Next.js application with tRPC must be deployed in order for the Expo app to communicate with the server in a production environment. + +#### Deploy to Vercel + +Let's deploy the Next.js application to [Vercel](https://vercel.com). If you've never deployed a Turborepo app there, don't worry, the steps are quite straightforward. You can also read the [official Turborepo guide](https://vercel.com/docs/concepts/monorepos/turborepo) on deploying to Vercel. + +1. Create a new project on Vercel, select the `apps/nextjs` folder as the root directory. Vercel's zero-config system should handle all configurations for you. + +2. Add your `DATABASE_URL` environment variable. + +3. Done! Your app should successfully deploy. Assign your domain and use that instead of `localhost` for the `url` in the Expo app so that your Expo app can communicate with your backend when you are not in development. + +### Auth Proxy + +The auth proxy is a Nitro server that proxies OAuth requests in preview deployments. This is required for the Next.js app to be able to authenticate users in preview deployments. The auth proxy is not used for OAuth requests in production deployments. To get it running, it's easiest to use Vercel Edge functions. See the [Nitro docs](https://nitro.unjs.io/deploy/providers/vercel#vercel-edge-functions) for how to deploy Nitro to Vercel. + +Then, there are some environment variables you need to set in order to get OAuth working: + +- For the Next.js app, set `AUTH_REDIRECT_PROXY_URL` to the URL of the auth proxy. +- For the auth proxy server, set `AUTH_REDIRECT_PROXY_URL` to the same as above, as well as `AUTH_DISCORD_ID`, `AUTH_DISCORD_SECRET` (or the equivalent for your OAuth provider(s)). Lastly, set `AUTH_SECRET` **to the same value as in the Next.js app** for preview environments. + +Read more about the setup in [the auth proxy README](./apps/auth-proxy/README.md). + +### Expo + +Deploying your Expo application works slightly differently compared to Next.js on the web. Instead of "deploying" your app online, you need to submit production builds of your app to app stores, like [Apple App Store](https://www.apple.com/app-store) and [Google Play](https://play.google.com/store/apps). You can read the full [guide to distributing your app](https://docs.expo.dev/distribution/introduction), including best practices, in the Expo docs. + +1. Make sure to modify the `getBaseUrl` function to point to your backend's production URL: + + + +2. Let's start by setting up [EAS Build](https://docs.expo.dev/build/introduction), which is short for Expo Application Services. The build service helps you create builds of your app, without requiring a full native development setup. The commands below are a summary of [Creating your first build](https://docs.expo.dev/build/setup). + + ```bash + # Install the EAS CLI + pnpm add -g eas-cli + + # Log in with your Expo account + eas login + + # Configure your Expo app + cd apps/expo + eas build:configure + ``` + +3. After the initial setup, you can create your first build. You can build for Android and iOS platforms and use different [`eas.json` build profiles](https://docs.expo.dev/build-reference/eas-json) to create production builds or development, or test builds. Let's make a production build for iOS. + + ```bash + eas build --platform ios --profile production + ``` + + > If you don't specify the `--profile` flag, EAS uses the `production` profile by default. + +4. Now that you have your first production build, you can submit this to the stores. [EAS Submit](https://docs.expo.dev/submit/introduction) can help you send the build to the stores. + + ```bash + eas submit --platform ios --latest + ``` + + > You can also combine build and submit in a single command, using `eas build ... --auto-submit`. + +5. Before you can get your app in the hands of your users, you'll have to provide additional information to the app stores. This includes screenshots, app information, privacy policies, etc. _While still in preview_, [EAS Metadata](https://docs.expo.dev/eas/metadata) can help you with most of this information. + +6. Once everything is approved, your users can finally enjoy your app. Let's say you spotted a small typo; you'll have to create a new build, submit it to the stores, and wait for approval before you can resolve this issue. In these cases, you can use EAS Update to quickly send a small bugfix to your users without going through this long process. Let's start by setting up EAS Update. + + The steps below summarize the [Getting started with EAS Update](https://docs.expo.dev/eas-update/getting-started/#configure-your-project) guide. + + ```bash + # Add the `expo-updates` library to your Expo app + cd apps/expo + pnpm expo install expo-updates + + # Configure EAS Update + eas update:configure + ``` + +7. Before we can send out updates to your app, you have to create a new build and submit it to the app stores. For every change that includes native APIs, you have to rebuild the app and submit the update to the app stores. See steps 2 and 3. + +8. Now that everything is ready for updates, let's create a new update for `production` builds. With the `--auto` flag, EAS Update uses your current git branch name and commit message for this update. See [How EAS Update works](https://docs.expo.dev/eas-update/how-eas-update-works/#publishing-an-update) for more information. + + ```bash + cd apps/expo + eas update --auto + ``` + + > Your OTA (Over The Air) updates must always follow the app store's rules. You can't change your app's primary functionality without getting app store approval. But this is a fast way to update your app for minor changes and bug fixes. + +9. Done! Now that you have created your production build, submitted it to the stores, and installed EAS Update, you are ready for anything! + +## References + +The stack originates from [create-t3-app](https://github.com/t3-oss/create-t3-app). + +A [blog post](https://jumr.dev/blog/t3-turbo) where I wrote how to migrate a T3 app into this. diff --git a/apps/auth-proxy/.env.example b/apps/auth-proxy/.env.example new file mode 100644 index 0000000..bdb4d55 --- /dev/null +++ b/apps/auth-proxy/.env.example @@ -0,0 +1,7 @@ + +AUTH_SECRET="" +AUTH_DISCORD_ID="" +AUTH_DISCORD_SECRET="" +AUTH_REDIRECT_PROXY_URL="" + +NITRO_PRESET="vercel_edge" \ No newline at end of file diff --git a/apps/auth-proxy/README.md b/apps/auth-proxy/README.md new file mode 100644 index 0000000..1a9876e --- /dev/null +++ b/apps/auth-proxy/README.md @@ -0,0 +1,16 @@ +# Auth Proxy + +This is a simple proxy server that enables OAuth authentication for preview environments. + +## Setup + +Deploy it somewhere (Vercel is a one-click, zero-config option) and set the following environment variables: + +- `AUTH_DISCORD_ID` - The Discord OAuth client ID +- `AUTH_DISCORD_SECRET` - The Discord OAuth client secret +- `AUTH_REDIRECT_PROXY_URL` - The URL of this proxy server +- `AUTH_SECRET` - Your secret + +Make sure the `AUTH_SECRET` and `AUTH_REDIRECT_PROXY_URL` match the values set for the main application's deployment for preview environments, and that you're using the same OAuth credentials for the proxy and the application's preview environment. The lines below shows what values should match eachother in both deployments. + +![Environment variables setup](https://github.com/t3-oss/create-t3-turbo/assets/51714798/5fadd3f5-f705-459a-82ab-559a3df881d0) diff --git a/apps/auth-proxy/package.json b/apps/auth-proxy/package.json new file mode 100644 index 0000000..4becb14 --- /dev/null +++ b/apps/auth-proxy/package.json @@ -0,0 +1,35 @@ +{ + "name": "@quotes/auth-proxy", + "private": true, + "type": "module", + "scripts": { + "build": "nitro build", + "clean": "rm -rf .turbo node_modules", + "dev": "nitro dev --port 3001", + "lint": "eslint .", + "format": "prettier --check . --ignore-path ../../.gitignore", + "typecheck": "tsc --noEmit" + }, + "dependencies": { + "@auth/core": "0.27.0" + }, + "devDependencies": { + "@quotes/eslint-config": "^0.2.0", + "@quotes/prettier-config": "^0.1.0", + "@quotes/tailwind-config": "^0.1.0", + "@quotes/tsconfig": "^0.1.0", + "@types/node": "^20.11.25", + "eslint": "^8.57.0", + "h3": "^1.11.1", + "nitropack": "^2.8.1", + "prettier": "^3.2.5", + "typescript": "^5.3.3" + }, + "eslintConfig": { + "root": true, + "extends": [ + "@quotes/eslint-config/base" + ] + }, + "prettier": "@quotes/prettier-config" +} diff --git a/apps/auth-proxy/routes/[...auth].ts b/apps/auth-proxy/routes/[...auth].ts new file mode 100644 index 0000000..c3a079c --- /dev/null +++ b/apps/auth-proxy/routes/[...auth].ts @@ -0,0 +1,17 @@ +import { Auth } from "@auth/core"; +import Discord from "@auth/core/providers/discord"; +import { eventHandler, toWebRequest } from "h3"; + +export default eventHandler(async (event) => + Auth(toWebRequest(event), { + secret: process.env.AUTH_SECRET, + trustHost: Boolean(process.env.VERCEL), + redirectProxyUrl: process.env.AUTH_REDIRECT_PROXY_URL, + providers: [ + Discord({ + clientId: process.env.AUTH_DISCORD_ID, + clientSecret: process.env.AUTH_DISCORD_SECRET, + }), + ], + }), +); diff --git a/apps/auth-proxy/tsconfig.json b/apps/auth-proxy/tsconfig.json new file mode 100644 index 0000000..acf0ec2 --- /dev/null +++ b/apps/auth-proxy/tsconfig.json @@ -0,0 +1,4 @@ +{ + "extends": "@quotes/tsconfig/base.json", + "include": ["routes"] +} diff --git a/apps/expo/.expo-shared/assets.json b/apps/expo/.expo-shared/assets.json new file mode 100644 index 0000000..1e6decf --- /dev/null +++ b/apps/expo/.expo-shared/assets.json @@ -0,0 +1,4 @@ +{ + "12bb71342c6255bbf50437ec8f4441c083f47cdb74bd89160c15e4f43e52a1cb": true, + "40b842e832070c58deac6aa9e08fa459302ee3f9da492c7e77d93d2fbf4a56fd": true +} diff --git a/apps/expo/app.config.ts b/apps/expo/app.config.ts new file mode 100644 index 0000000..053fcb3 --- /dev/null +++ b/apps/expo/app.config.ts @@ -0,0 +1,42 @@ +import type { ConfigContext, ExpoConfig } from "expo/config"; + +export default ({ config }: ConfigContext): ExpoConfig => ({ + ...config, + name: "expo", + slug: "expo", + scheme: "expo", + version: "0.1.0", + orientation: "portrait", + icon: "./assets/icon.png", + userInterfaceStyle: "automatic", + splash: { + image: "./assets/icon.png", + resizeMode: "contain", + backgroundColor: "#1F104A", + }, + updates: { + fallbackToCacheTimeout: 0, + }, + assetBundlePatterns: ["**/*"], + ios: { + bundleIdentifier: "your.bundle.identifier", + supportsTablet: true, + }, + android: { + package: "your.bundle.identifier", + adaptiveIcon: { + foregroundImage: "./assets/icon.png", + backgroundColor: "#1F104A", + }, + }, + // extra: { + // eas: { + // projectId: "your-eas-project-id", + // }, + // }, + experiments: { + tsconfigPaths: true, + typedRoutes: true, + }, + plugins: ["expo-router"], +}); diff --git a/apps/expo/assets/icon.png b/apps/expo/assets/icon.png new file mode 100644 index 0000000..67917f5 Binary files /dev/null and b/apps/expo/assets/icon.png differ diff --git a/apps/expo/babel.config.js b/apps/expo/babel.config.js new file mode 100644 index 0000000..95b1393 --- /dev/null +++ b/apps/expo/babel.config.js @@ -0,0 +1,11 @@ +/** @type {import("@babel/core").ConfigFunction} */ +module.exports = (api) => { + api.cache(true); + return { + presets: [ + ["babel-preset-expo", { jsxImportSource: "nativewind" }], + "nativewind/babel", + ], + plugins: ["react-native-reanimated/plugin"], + }; +}; diff --git a/apps/expo/eas.json b/apps/expo/eas.json new file mode 100644 index 0000000..607de32 --- /dev/null +++ b/apps/expo/eas.json @@ -0,0 +1,31 @@ +{ + "cli": { + "version": ">= 4.1.2" + }, + "build": { + "base": { + "node": "18.16.1", + "ios": { + "resourceClass": "m-medium" + } + }, + "development": { + "extends": "base", + "developmentClient": true, + "distribution": "internal" + }, + "preview": { + "extends": "base", + "distribution": "internal", + "ios": { + "simulator": true + } + }, + "production": { + "extends": "base" + } + }, + "submit": { + "production": {} + } +} diff --git a/apps/expo/metro.config.js b/apps/expo/metro.config.js new file mode 100644 index 0000000..4944183 --- /dev/null +++ b/apps/expo/metro.config.js @@ -0,0 +1,55 @@ +// Learn more: https://docs.expo.dev/guides/monorepos/ +const { getDefaultConfig } = require("expo/metro-config"); +const { FileStore } = require("metro-cache"); +const { withNativeWind } = require("nativewind/metro"); + +const path = require("path"); + +module.exports = withTurborepoManagedCache( + withMonorepoPaths( + withNativeWind(getDefaultConfig(__dirname), { + input: "./src/styles.css", + configPath: "./tailwind.config.ts", + }), + ), +); + +/** + * Add the monorepo paths to the Metro config. + * This allows Metro to resolve modules from the monorepo. + * + * @see https://docs.expo.dev/guides/monorepos/#modify-the-metro-config + * @param {import('expo/metro-config').MetroConfig} config + * @returns {import('expo/metro-config').MetroConfig} + */ +function withMonorepoPaths(config) { + const projectRoot = __dirname; + const workspaceRoot = path.resolve(projectRoot, "../.."); + + // #1 - Watch all files in the monorepo + config.watchFolders = [workspaceRoot]; + + // #2 - Resolve modules within the project's `node_modules` first, then all monorepo modules + config.resolver.nodeModulesPaths = [ + path.resolve(projectRoot, "node_modules"), + path.resolve(workspaceRoot, "node_modules"), + ]; + + return config; +} + +/** + * Move the Metro cache to the `node_modules/.cache/metro` folder. + * This repository configured Turborepo to use this cache location as well. + * If you have any environment variables, you can configure Turborepo to invalidate it when needed. + * + * @see https://turbo.build/repo/docs/reference/configuration#env + * @param {import('expo/metro-config').MetroConfig} config + * @returns {import('expo/metro-config').MetroConfig} + */ +function withTurborepoManagedCache(config) { + config.cacheStores = [ + new FileStore({ root: path.join(__dirname, "node_modules/.cache/metro") }), + ]; + return config; +} diff --git a/apps/expo/package.json b/apps/expo/package.json new file mode 100644 index 0000000..b25a990 --- /dev/null +++ b/apps/expo/package.json @@ -0,0 +1,68 @@ +{ + "name": "@quotes/expo", + "version": "0.1.0", + "private": true, + "main": "expo-router/entry", + "scripts": { + "clean": "git clean -xdf .expo .turbo node_modules", + "dev": "expo start", + "dev:android": "expo start --android", + "dev:ios": "expo start --ios", + "android": "expo run:android", + "ios": "expo run:ios", + "format": "prettier --check . --ignore-path ../../.gitignore", + "lint": "eslint .", + "typecheck": "tsc --noEmit" + }, + "dependencies": { + "@expo/metro-config": "^0.17.4", + "@shopify/flash-list": "1.6.3", + "@tanstack/react-query": "^5.22.2", + "@trpc/client": "11.0.0-next-beta.294", + "@trpc/react-query": "11.0.0-next-beta.294", + "@trpc/server": "11.0.0-next-beta.294", + "expo": "~50.0.7", + "expo-constants": "~15.4.5", + "expo-linking": "~6.2.2", + "expo-router": "~3.4.7", + "expo-splash-screen": "~0.26.4", + "expo-status-bar": "~1.11.1", + "nativewind": "~4.0.36", + "react": "18.2.0", + "react-dom": "18.2.0", + "react-native": "~0.73.5", + "react-native-css-interop": "~0.0.13", + "react-native-gesture-handler": "~2.14.0", + "react-native-reanimated": "~3.6.3", + "react-native-safe-area-context": "~4.8.2", + "react-native-screens": "~3.29.0", + "superjson": "2.2.1" + }, + "devDependencies": { + "@quotes/api": "^0.1.0", + "@quotes/eslint-config": "^0.2.0", + "@quotes/prettier-config": "^0.1.0", + "@quotes/tailwind-config": "^0.1.0", + "@quotes/tsconfig": "^0.1.0", + "@babel/core": "^7.23.9", + "@babel/preset-env": "^7.23.9", + "@babel/runtime": "^7.23.9", + "@types/babel__core": "^7.20.5", + "@types/react": "^18.2.57", + "eslint": "^8.57.0", + "prettier": "^3.2.5", + "tailwindcss": "^3.4.1", + "typescript": "^5.3.3" + }, + "eslintConfig": { + "root": true, + "extends": [ + "@quotes/eslint-config/base", + "@quotes/eslint-config/react" + ], + "ignorePatterns": [ + "expo-plugins/**" + ] + }, + "prettier": "@quotes/prettier-config" +} diff --git a/apps/expo/src/app/_layout.tsx b/apps/expo/src/app/_layout.tsx new file mode 100644 index 0000000..87c5565 --- /dev/null +++ b/apps/expo/src/app/_layout.tsx @@ -0,0 +1,33 @@ +import { Stack } from "expo-router"; +import { StatusBar } from "expo-status-bar"; + +import { TRPCProvider } from "~/utils/api"; + +import "../styles.css"; + +import { useColorScheme } from "nativewind"; + +// This is the main layout of the app +// It wraps your pages with the providers they need +export default function RootLayout(): React.ReactElement { + const { colorScheme } = useColorScheme(); + return ( + + {/* + The Stack component displays the current page. + It also allows you to configure your screens + */} + + + + ); +} diff --git a/apps/expo/src/app/index.tsx b/apps/expo/src/app/index.tsx new file mode 100644 index 0000000..c9503e0 --- /dev/null +++ b/apps/expo/src/app/index.tsx @@ -0,0 +1,151 @@ +import { useState } from "react"; +import { Pressable, Text, TextInput, View } from "react-native"; +import { SafeAreaView } from "react-native-safe-area-context"; +import { Link, Stack } from "expo-router"; +import { FlashList } from "@shopify/flash-list"; + +import type { RouterOutputs } from "~/utils/api"; +import { api } from "~/utils/api"; + +function PostCard(props: { + post: RouterOutputs["post"]["all"][number]; + onDelete: () => void; +}): React.ReactElement { + return ( + + + + + + {/* eslint-disable-next-line @typescript-eslint/no-unsafe-member-access -- itll be fine */} + {props.post.title} + + {/* eslint-disable-next-line @typescript-eslint/no-unsafe-member-access -- itll be fine */} + {props.post.content} + + + + + Delete + + + ); +} + +function CreatePost(): React.ReactElement { + const utils = api.useUtils(); + + const [title, setTitle] = useState(""); + const [content, setContent] = useState(""); + + const { mutate, error } = api.post.create.useMutation({ + async onSuccess() { + setTitle(""); + setContent(""); + await utils.post.all.invalidate(); + }, + }); + + return ( + + + {error?.data?.zodError?.fieldErrors.title ? ( + + {error.data.zodError.fieldErrors.title} + + ) : null} + + {error?.data?.zodError?.fieldErrors.content ? ( + + {error.data.zodError.fieldErrors.content} + + ) : null} + { + mutate({ + title, + content, + }); + }} + > + Create + + {error?.data?.code === "UNAUTHORIZED" && ( + + You need to be logged in to create a post + + )} + + ); +} + +export default function Index(): React.ReactElement { + const utils = api.useUtils(); + + const postQuery = api.post.all.useQuery(); + + const deletePostMutation = api.post.delete.useMutation({ + onSettled: () => utils.post.all.invalidate().then(), + }); + + return ( + + {/* Changes page title visible on the header */} + + + + Turbo Template + + + void utils.post.all.invalidate()} + className="flex items-center rounded-lg bg-primary p-2" + > + Refresh posts + + + + + Press on a post + + + + } + renderItem={(p) => ( + { + deletePostMutation.mutate((p.item as { id: number }).id); + }} + /> + )} + /> + + + + + ); +} diff --git a/apps/expo/src/app/post/[id].tsx b/apps/expo/src/app/post/[id].tsx new file mode 100644 index 0000000..3a1bc57 --- /dev/null +++ b/apps/expo/src/app/post/[id].tsx @@ -0,0 +1,29 @@ +import { SafeAreaView, Text, View } from "react-native"; +import { Stack, useGlobalSearchParams } from "expo-router"; + +import { api } from "~/utils/api"; + +export default function Post(): React.ReactElement { + const { id } = useGlobalSearchParams(); + if (!id || typeof id !== "string") throw new Error("unreachable"); + // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment -- itll be ok + const { data } = api.post.byId.useQuery({ id: parseInt(id) }); + + // eslint-disable-next-line react/jsx-no-useless-fragment -- they're placeholders + if (!data) return <>; + + return ( + + {/* eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-member-access -- its fine */} + + + + {/* eslint-disable-next-line @typescript-eslint/no-unsafe-member-access -- its fine */} + {data.title} + + {/* eslint-disable-next-line @typescript-eslint/no-unsafe-member-access -- its fine */} + {data.content} + + + ); +} diff --git a/apps/expo/src/styles.css b/apps/expo/src/styles.css new file mode 100644 index 0000000..31d38d9 --- /dev/null +++ b/apps/expo/src/styles.css @@ -0,0 +1,50 @@ +@tailwind base; +@tailwind components; +@tailwind utilities; + +:root { + --background: 0 0% 100%; + --foreground: 240 10% 3.9%; + --card: 0 0% 100%; + --card-foreground: 240 10% 3.9%; + --popover: 0 0% 100%; + --popover-foreground: 240 10% 3.9%; + --primary: 327 66% 69%; + --primary-foreground: 337 65.5% 17.1%; + --secondary: 240 4.8% 95.9%; + --secondary-foreground: 240 5.9% 10%; + --muted: 240 4.8% 95.9%; + --muted-foreground: 240 3.8% 46.1%; + --accent: 240 4.8% 95.9%; + --accent-foreground: 240 5.9% 10%; + --destructive: 0 72.22% 50.59%; + --destructive-foreground: 0 0% 98%; + --border: 240 5.9% 90%; + --input: 240 5.9% 90%; + --ring: 240 5% 64.9%; + --radius: 0.5rem; +} + +@media (prefers-color-scheme: dark) { + :root { + --background: 240 10% 3.9%; + --foreground: 0 0% 98%; + --card: 240 10% 3.9%; + --card-foreground: 0 0% 98%; + --popover: 240 10% 3.9%; + --popover-foreground: 0 0% 98%; + --primary: 327 66% 69%; + --primary-foreground: 337 65.5% 17.1%; + --secondary: 240 3.7% 15.9%; + --secondary-foreground: 0 0% 98%; + --muted: 240 3.7% 15.9%; + --muted-foreground: 240 5% 64.9%; + --accent: 240 3.7% 15.9%; + --accent-foreground: 0 0% 98%; + --destructive: 0 62.8% 30.6%; + --destructive-foreground: 0 85.7% 97.3%; + --border: 240 3.7% 15.9%; + --input: 240 3.7% 15.9%; + --ring: 240 4.9% 83.9%; + } +} diff --git a/apps/expo/src/types/nativewind-env.d.ts b/apps/expo/src/types/nativewind-env.d.ts new file mode 100644 index 0000000..a13e313 --- /dev/null +++ b/apps/expo/src/types/nativewind-env.d.ts @@ -0,0 +1 @@ +/// diff --git a/apps/expo/src/utils/api.tsx b/apps/expo/src/utils/api.tsx new file mode 100644 index 0000000..dfe22cd --- /dev/null +++ b/apps/expo/src/utils/api.tsx @@ -0,0 +1,79 @@ +import type { AppRouter } from "@quotes/api"; +import { useState } from "react"; +import Constants from "expo-constants"; +import { QueryClient, QueryClientProvider } from "@tanstack/react-query"; +import { httpBatchLink, loggerLink } from "@trpc/client"; +import { createTRPCReact } from "@trpc/react-query"; +import superjson from "superjson"; + +/** + * A set of typesafe hooks for consuming your API. + */ +export const api = createTRPCReact(); +export { type RouterInputs, type RouterOutputs } from "@quotes/api"; + +/** + * Extend this function when going to production by + * setting the baseUrl to your production API URL. + */ +const getBaseUrl = (): string => { + /** + * Gets the IP address of your host-machine. If it cannot automatically find it, + * you'll have to manually set it. NOTE: Port 3000 should work for most but confirm + * you don't have anything else running on it, or you'd have to change it. + * + * **NOTE**: This is only for development. In production, you'll want to set the + * baseUrl to your production API URL. + */ + const debuggerHost = Constants.expoConfig?.hostUri; + const localhost = debuggerHost?.split(":")[0]; + + if (!localhost) { + // return "https://turbo.t3.gg"; + throw new Error( + "Failed to get localhost. Please point to your production server.", + ); + } + return `http://${localhost}:3000`; +}; + +/** + * A wrapper for your app that provides the TRPC context. + * Use only in _app.tsx + */ +export function TRPCProvider(props: { + children: React.ReactNode; +}): React.ReactElement { + // eslint-disable-next-line react/hook-use-state -- its fine + const [queryClient] = useState(() => new QueryClient()); + // eslint-disable-next-line react/hook-use-state -- its fine + const [trpcClient] = useState(() => + api.createClient({ + links: [ + loggerLink({ + enabled: (opts) => + process.env.NODE_ENV === "development" || + (opts.direction === "down" && opts.result instanceof Error), + colorMode: "ansi", + }), + httpBatchLink({ + transformer: superjson, + url: `${getBaseUrl()}/api/trpc`, + headers() { + const headers = new Map(); + headers.set("x-trpc-source", "expo-react"); + return Object.fromEntries(headers); + }, + }), + ], + }), + ); + + return ( + + + {props.children} + + + ); +} diff --git a/apps/expo/tailwind.config.ts b/apps/expo/tailwind.config.ts new file mode 100644 index 0000000..16cc52b --- /dev/null +++ b/apps/expo/tailwind.config.ts @@ -0,0 +1,9 @@ +import type { Config } from "tailwindcss"; +import baseConfig from "@quotes/tailwind-config/native"; +// @ts-expect-error - no types +import nativewind from "nativewind/preset"; + +export default { + content: ["./src/**/*.{ts,tsx}"], + presets: [baseConfig, nativewind], +} satisfies Config; diff --git a/apps/expo/tsconfig.json b/apps/expo/tsconfig.json new file mode 100644 index 0000000..c3a736c --- /dev/null +++ b/apps/expo/tsconfig.json @@ -0,0 +1,14 @@ +{ + "extends": ["@quotes/tsconfig/base.json"], + "compilerOptions": { + "baseUrl": ".", + "paths": { + "~/*": ["./src/*"] + }, + "jsx": "react-native", + "tsBuildInfoFile": "node_modules/.cache/tsbuildinfo.json", + "types": ["nativewind/types"] + }, + "include": ["src", "*.ts", "*.js", ".expo/types/**/*.ts", "expo-env.d.ts"], + "exclude": ["node_modules"] +} diff --git a/apps/nextjs/README.md b/apps/nextjs/README.md new file mode 100644 index 0000000..437b0b8 --- /dev/null +++ b/apps/nextjs/README.md @@ -0,0 +1,28 @@ +# Create T3 App + +This is a [T3 Stack](https://create.t3.gg/) project bootstrapped with `create-t3-app`. + +## What's next? How do I make an app with this? + +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. + +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. + +- [Next.js](https://nextjs.org) +- [NextAuth.js](https://next-auth.js.org) +- [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) and [Docker](https://create.t3.gg/en/deployment/docker) for more information. diff --git a/apps/nextjs/next.config.js b/apps/nextjs/next.config.js new file mode 100644 index 0000000..61174c9 --- /dev/null +++ b/apps/nextjs/next.config.js @@ -0,0 +1,28 @@ +import { fileURLToPath } from "url"; +import _jiti from "jiti"; + +const jiti = _jiti(fileURLToPath(import.meta.url)); + +// Import env files to validate at build time. Use jiti so we can load .ts files in here. +jiti("./src/env"); +jiti("@quotes/auth/env"); + +/** @type {import("next").NextConfig} */ +const config = { + reactStrictMode: true, + + /** Enables hot reloading for local packages without a build step */ + transpilePackages: [ + "@quotes/api", + "@quotes/auth", + "@quotes/db", + "@quotes/ui", + "@quotes/validators", + ], + + /** We already do linting and typechecking as separate tasks in CI */ + eslint: { ignoreDuringBuilds: true }, + typescript: { ignoreBuildErrors: true }, +}; + +export default config; diff --git a/apps/nextjs/package.json b/apps/nextjs/package.json new file mode 100644 index 0000000..2e62879 --- /dev/null +++ b/apps/nextjs/package.json @@ -0,0 +1,59 @@ +{ + "name": "@quotes/nextjs", + "version": "0.1.0", + "private": true, + "type": "module", + "scripts": { + "build": "pnpm with-env next build", + "clean": "git clean -xdf .next .turbo node_modules", + "dev": "pnpm with-env next dev", + "format": "prettier --check . --ignore-path ../../.gitignore", + "lint": "dotenv -v SKIP_ENV_VALIDATION=1 next lint", + "start": "pnpm with-env next start", + "typecheck": "tsc --noEmit", + "with-env": "dotenv -e ../../.env --" + }, + "dependencies": { + "@quotes/api": "^0.1.0", + "@quotes/auth": "^0.1.0", + "@quotes/db": "^0.1.0", + "@quotes/ui": "^0.1.0", + "@quotes/validators": "^0.1.0", + "@t3-oss/env-nextjs": "^0.9.2", + "@tabler/icons-react": "^3.1.0", + "@tanstack/react-query": "^5.22.2", + "@trpc/client": "11.0.0-next-beta.294", + "@trpc/react-query": "11.0.0-next-beta.294", + "@trpc/server": "11.0.0-next-beta.294", + "geist": "^1.2.2", + "next": "^14.1.0", + "react": "18.2.0", + "react-dom": "18.2.0", + "superjson": "2.2.1", + "zod": "^3.22.4" + }, + "devDependencies": { + "@quotes/eslint-config": "^0.2.0", + "@quotes/prettier-config": "^0.1.0", + "@quotes/tailwind-config": "^0.1.0", + "@quotes/tsconfig": "^0.1.0", + "@types/node": "^20.11.25", + "@types/react": "^18.2.57", + "@types/react-dom": "^18.2.19", + "dotenv-cli": "^7.3.0", + "eslint": "^8.57.0", + "jiti": "^1.21.0", + "prettier": "^3.2.5", + "tailwindcss": "^3.4.1", + "typescript": "^5.3.3" + }, + "eslintConfig": { + "root": true, + "extends": [ + "@quotes/eslint-config/base", + "@quotes/eslint-config/nextjs", + "@quotes/eslint-config/react" + ] + }, + "prettier": "@quotes/prettier-config" +} diff --git a/apps/nextjs/postcss.config.cjs b/apps/nextjs/postcss.config.cjs new file mode 100644 index 0000000..ee5f90b --- /dev/null +++ b/apps/nextjs/postcss.config.cjs @@ -0,0 +1,5 @@ +module.exports = { + plugins: { + tailwindcss: {}, + }, +}; diff --git a/apps/nextjs/public/favicon.ico b/apps/nextjs/public/favicon.ico new file mode 100644 index 0000000..a84d91c Binary files /dev/null and b/apps/nextjs/public/favicon.ico differ diff --git a/apps/nextjs/src/app/_components/auth-showcase.tsx b/apps/nextjs/src/app/_components/auth-showcase.tsx new file mode 100644 index 0000000..3708098 --- /dev/null +++ b/apps/nextjs/src/app/_components/auth-showcase.tsx @@ -0,0 +1,45 @@ +import { auth, signIn, signOut } from "@quotes/auth"; +import { Button } from "@quotes/ui/button"; +import { IconBrandDiscord } from "@tabler/icons-react"; + +export async function AuthShowcase(): Promise { + const session = await auth(); + + if (!session) { + return ( +
+ +
+ ); + } + + return ( +
+

+ {/* eslint-disable-next-line @typescript-eslint/no-unnecessary-condition -- It's better to be safe then sorry */} + {session ? Logged in as {session.user.name} : null} +

+ +
+ +
+
+ ); +} diff --git a/apps/nextjs/src/app/_components/posts.tsx b/apps/nextjs/src/app/_components/posts.tsx new file mode 100644 index 0000000..f80b618 --- /dev/null +++ b/apps/nextjs/src/app/_components/posts.tsx @@ -0,0 +1,180 @@ +"use client"; + +import { use } from "react"; +import { Button } from "@quotes/ui/button"; +import { Card, CardContent, CardHeader, CardTitle } from "@quotes/ui/card"; +import { + Form, + FormControl, + FormField, + FormItem, + FormMessage, + useForm, +} from "@quotes/ui/form"; +import { Input } from "@quotes/ui/input"; +import { Skeleton } from "@quotes/ui/skeleton"; +import { Textarea } from "@quotes/ui/textarea"; +import { toast } from "@quotes/ui/toast"; +import { CreatePostSchema } from "@quotes/validators"; +import { IconTrash } from "@tabler/icons-react"; + +import { api } from "~/trpc/react"; + +export function CreatePostForm(): React.ReactElement { + const form = useForm({ + schema: CreatePostSchema, + defaultValues: { + content: "", + title: "", + }, + }); + + const utils = api.useUtils(); + const createPost = api.post.create.useMutation({ + onSuccess: async () => { + form.reset(); + await utils.post.invalidate(); + }, + onError: (err) => { + toast.error( + err.data?.code === "UNAUTHORIZED" + ? "You must be logged in to post" + : "Failed to create post", + ); + }, + }); + + function submit(data: { title: string; content: string }): void { + toast.promise(createPost.mutateAsync(data), { + loading: "Creating post...", + success: "Post created!", + error: "Failed to create post!", + }); + } + + return ( +
+ { + submit(data); + })} + > + ( + + + + + + + )} + /> + ( + + +