From 3668d83a571c0b6400762e5e6f9d8e327766bebc Mon Sep 17 00:00:00 2001 From: Emilio Heinzmann Date: Mon, 13 May 2024 23:43:14 -0300 Subject: [PATCH 01/20] feat: basic email signin --- .env.example | 5 +++++ package.json | 1 + src/app/signin/page.tsx | 5 ++++- src/env.js | 10 ++++++++++ src/server/auth.ts | 19 ++++++++++++++++--- yarn.lock | 6 ++++++ 6 files changed, 42 insertions(+), 4 deletions(-) diff --git a/.env.example b/.env.example index 78f2273..6f71e0f 100644 --- a/.env.example +++ b/.env.example @@ -23,6 +23,11 @@ NEXTAUTH_URL="http://localhost:3000" # Next Auth Google Sign-In GOOGLE_CLIENT_ID="" GOOGLE_CLIENT_SECRET="" +EMAIL_HOST="" +EMAIL_PORT="" +EMAIL_USER="" +EMAIL_PASS="" +EMAIL_FROM="" # Postgres only used on Docker POSTGRES_DB="sos-pet" diff --git a/package.json b/package.json index 6974875..92fadf9 100644 --- a/package.json +++ b/package.json @@ -38,6 +38,7 @@ "next": "^14.2.1", "next-auth": "^4.24.6", "next-themes": "^0.3.0", + "nodemailer": "^6.9.13", "react": "18.2.0", "react-dom": "18.2.0", "react-hook-form": "^7.51.4", diff --git a/src/app/signin/page.tsx b/src/app/signin/page.tsx index ded9df1..8cab2b8 100644 --- a/src/app/signin/page.tsx +++ b/src/app/signin/page.tsx @@ -17,7 +17,10 @@ export default async function SigninPage({ searchParams }: SigninPageProps) { redirect(searchParams.callbackUrl ?? "/"); } - const providers = [{ id: "google", name: "Google" }]; + const providers = [ + { id: "google", name: "Google" }, + { id: "email", name: "Email" }, + ]; return (
diff --git a/src/env.js b/src/env.js index 2124bb8..4ce7941 100644 --- a/src/env.js +++ b/src/env.js @@ -24,6 +24,11 @@ export const env = createEnv({ ), GOOGLE_CLIENT_ID: z.string(), GOOGLE_CLIENT_SECRET: z.string(), + EMAIL_HOST: z.string(), + EMAIL_PORT: z.string(), + EMAIL_USER: z.string(), + EMAIL_PASSWORD: z.string(), + EMAIL_FROM: z.string(), }, /** @@ -46,6 +51,11 @@ export const env = createEnv({ NEXTAUTH_URL: process.env.NEXTAUTH_URL, GOOGLE_CLIENT_ID: process.env.GOOGLE_CLIENT_ID, GOOGLE_CLIENT_SECRET: process.env.GOOGLE_CLIENT_SECRET, + EMAIL_HOST: process.env.EMAIL_HOST, + EMAIL_PORT: process.env.EMAIL_PORT, + EMAIL_USER: process.env.EMAIL_USER, + EMAIL_PASSWORD: process.env.EMAIL_PASSWORD, + EMAIL_FROM: process.env.EMAIL_FROM, }, /** * Run `build` or `dev` with `SKIP_ENV_VALIDATION` to skip env validation. This is especially diff --git a/src/server/auth.ts b/src/server/auth.ts index e27b088..2c4ddc9 100644 --- a/src/server/auth.ts +++ b/src/server/auth.ts @@ -6,6 +6,7 @@ import { } from "next-auth"; import { type Adapter } from "next-auth/adapters"; import GoogleProvider from "next-auth/providers/google"; +import EmailProvider from "next-auth/providers/email"; import { env } from "~/env"; import { db } from "~/server/db"; @@ -41,9 +42,9 @@ export const authOptions: NextAuthOptions = { colorScheme: "light", logo: "/logo-horizontal.png", }, - pages: { - signIn: "/signin", - }, + // pages: { + // signIn: "/signin", + // }, callbacks: { session: ({ session, user }) => ({ ...session, @@ -59,6 +60,18 @@ export const authOptions: NextAuthOptions = { clientId: env.GOOGLE_CLIENT_ID, clientSecret: env.GOOGLE_CLIENT_SECRET, }), + EmailProvider({ + server: { + host: env.EMAIL_HOST, + port: env.EMAIL_PORT, + auth: { + user: env.EMAIL_USER, + pass: env.EMAIL_PASSWORD, + }, + secure: true, + }, + from: env.EMAIL_FROM, + }), /** * ...add more providers here. * diff --git a/yarn.lock b/yarn.lock index 189838b..a13bed2 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2544,6 +2544,11 @@ next@^14.2.1: "@next/swc-win32-ia32-msvc" "14.2.3" "@next/swc-win32-x64-msvc" "14.2.3" +nodemailer@^6.9.13: + version "6.9.13" + resolved "https://registry.yarnpkg.com/nodemailer/-/nodemailer-6.9.13.tgz#5b292bf1e92645f4852ca872c56a6ba6c4a3d3d6" + integrity sha512-7o38Yogx6krdoBf3jCAqnIN4oSQFx+fMa0I7dK1D+me9kBxx12D+/33wSb+fhOCtIxvYJ+4x4IMEhmhCKfAiOA== + normalize-path@^3.0.0, normalize-path@~3.0.0: version "3.0.0" resolved "https://registry.npmjs.org/normalize-path/-/normalize-path-3.0.0.tgz" @@ -3143,6 +3148,7 @@ streamsearch@^1.1.0: integrity sha512-Mcc5wHehp9aXz1ax6bZUyY5afg9u2rv5cqQI3mRrYkGC8rW2hM02jWuwjtL++LS5qinSyhj2QfLyNsuc+VsExg== "string-width-cjs@npm:string-width@^4.2.0", string-width@^4.1.0: + name string-width-cjs version "4.2.3" resolved "https://registry.npmjs.org/string-width/-/string-width-4.2.3.tgz" integrity sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g== From c8e4f52b0ae099fde7204bbff83f5a3ff2f61793 Mon Sep 17 00:00:00 2001 From: Eduarda Pinheiro Date: Wed, 15 May 2024 22:03:04 -0300 Subject: [PATCH 02/20] feat: moves social session to the bottom and vacancies availability to the top --- src/components/card/index.tsx | 72 +++++++++++++++++------------------ 1 file changed, 34 insertions(+), 38 deletions(-) diff --git a/src/components/card/index.tsx b/src/components/card/index.tsx index 903b2fd..7ec48e6 100644 --- a/src/components/card/index.tsx +++ b/src/components/card/index.tsx @@ -22,35 +22,15 @@ export function Card({ shelter }: Props) { return ( - -
-

{shelter.name}

-
- {shelter.facebook && ( - } - label="Facebook" - /> - )} - - {shelter.instagram && ( - } - label="Instagram" - /> - )} - - {shelter.twitter && ( - } - label="Twitter" - /> - )} -
-
+ +

{shelter.name}

+ {availableVacancies > 0 ? ( +

+ Vagas disponíveis: {availableVacancies} +

+ ) : ( +

Vagas esgotadas

+ )} - {availableVacancies > 0 ? ( -

- Vagas disponíveis: {availableVacancies} -

- ) : ( -

- Vagas esgotadas -

- )} +
+ {shelter.facebook && ( + } + label="Facebook" + /> + )} + + {shelter.instagram && ( + } + label="Instagram" + /> + )} + + {shelter.twitter && ( + } + label="Twitter" + /> + )} +
); From a3d9079c70062074323f00bfbf87f73923eb8e5c Mon Sep 17 00:00:00 2001 From: Marciel Torres Date: Fri, 17 May 2024 17:01:34 -0300 Subject: [PATCH 03/20] Adding github project link --- README.md | 2 +- src/app/about/page.tsx | 2 ++ src/components/footer/index.tsx | 10 +++++++++- 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 82d961e..d5e12aa 100644 --- a/README.md +++ b/README.md @@ -12,6 +12,6 @@ Com o SOS Pet, as pessoas que resgatam animais de enchentes podem rapidamente en 1. Instale as dependências 1. Crie um arquivo `.env` baseando se no `.env.example` 1. Assegure se de preencher todas as variáveis ambiente. -1. Suba o baco de dados: `docker compose up -d` +1. Suba o baco de dados: `docker-compose up -d` 1. Rode as migrations: `npx prisma migrate dev` 1. Rode o projeto com o script `dev` disponível no `package.json` diff --git a/src/app/about/page.tsx b/src/app/about/page.tsx index 0e50f5b..f4cd73d 100644 --- a/src/app/about/page.tsx +++ b/src/app/about/page.tsx @@ -61,6 +61,8 @@ export default function About() { transformar um momento de crise em uma oportunidade para fazer a diferença na vida de um animal. Juntos, podemos salvar vidas e construir um futuro mais seguro para nossos amigos de quatro patas. + Além disso, esse projeto tem seu código fonte aberto e disponível para colaboração: + https://github.com/emiliosheinz/sos-pet

diff --git a/src/components/footer/index.tsx b/src/components/footer/index.tsx index 9db2522..0b5862a 100644 --- a/src/components/footer/index.tsx +++ b/src/components/footer/index.tsx @@ -1,6 +1,6 @@ import Image from "next/image"; import Link from "next/link"; -import { FaInstagram } from "react-icons/fa"; +import { FaInstagram, FaGithub } from "react-icons/fa"; export function Footer() { return ( @@ -15,6 +15,13 @@ export function Footer() { />
+ + sos-pet + Políticas de privacidade +
From 38177e4a5f3408cffdcee5373709f42626424278 Mon Sep 17 00:00:00 2001 From: Emilio Heinzmann Date: Sat, 18 May 2024 10:26:28 -0300 Subject: [PATCH 04/20] ci: trigger lint type-check and build workflow on pull request target --- .github/workflows/lint-type-check-and-build.yaml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/.github/workflows/lint-type-check-and-build.yaml b/.github/workflows/lint-type-check-and-build.yaml index 0577526..d8d78df 100644 --- a/.github/workflows/lint-type-check-and-build.yaml +++ b/.github/workflows/lint-type-check-and-build.yaml @@ -1,7 +1,7 @@ name: 🚀 Lint, Type Check, and Build on: - pull_request: + pull_request_target: branches: - main - dev @@ -9,9 +9,12 @@ on: jobs: lint-type-check-and-build: runs-on: ubuntu-latest + name: Lint, Type Check, and Build steps: - name: Checkout code uses: actions/checkout@v4 + with: + ref: ${{ github.event.pull_request.head.sha }} - name: Set up Node.js uses: actions/setup-node@v4 From 1c3513b4a48fd551e606828d8361541ed2620ccd Mon Sep 17 00:00:00 2001 From: Emilio Heinzmann Date: Sat, 18 May 2024 10:30:46 -0300 Subject: [PATCH 05/20] ci: usa .env.example to define environment variables --- .env.example | 8 ++++---- .github/workflows/lint-type-check-and-build.yaml | 6 ++---- 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/.env.example b/.env.example index 44051e0..4e08b10 100644 --- a/.env.example +++ b/.env.example @@ -3,14 +3,14 @@ DATABASE_URL="postgresql://postgres:password@localhost:5432/sos-pet" # Next Auth NEXTAUTH_URL="http://localhost:3000" -NEXTAUTH_SECRET="nextauthsecret" +NEXTAUTH_SECRET="nextauth-secret" # Next Auth Providers -GOOGLE_CLIENT_ID="" -GOOGLE_CLIENT_SECRET="" +GOOGLE_CLIENT_ID="google-client-id" +GOOGLE_CLIENT_SECRET="google-client-secret" # Google Maps -NEXT_PUBLIC_GOOGLE_MAPS_API_KEY="" +NEXT_PUBLIC_GOOGLE_MAPS_API_KEY="google-maps-api-key" # Docker related variables, not used on Next.js POSTGRES_DB="sos-pet" diff --git a/.github/workflows/lint-type-check-and-build.yaml b/.github/workflows/lint-type-check-and-build.yaml index d8d78df..1fd6680 100644 --- a/.github/workflows/lint-type-check-and-build.yaml +++ b/.github/workflows/lint-type-check-and-build.yaml @@ -1,7 +1,7 @@ name: 🚀 Lint, Type Check, and Build on: - pull_request_target: + pull_request: branches: - main - dev @@ -13,8 +13,6 @@ jobs: steps: - name: Checkout code uses: actions/checkout@v4 - with: - ref: ${{ github.event.pull_request.head.sha }} - name: Set up Node.js uses: actions/setup-node@v4 @@ -23,7 +21,7 @@ jobs: cache: "yarn" - name: Setup .env file - run: echo "${{ secrets.DOT_ENV_FILE_CONTENT }}" > .env + run: cat .env.example > .env - name: Install dependencies run: yarn From 8f7516f411430d0d10c5cc88ba7ae93cd8e2f542 Mon Sep 17 00:00:00 2001 From: Emilio Heinzmann Date: Sat, 18 May 2024 10:32:10 -0300 Subject: [PATCH 06/20] docs: add comment about usage of .env.example --- .github/workflows/lint-type-check-and-build.yaml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/lint-type-check-and-build.yaml b/.github/workflows/lint-type-check-and-build.yaml index 1fd6680..c6b57b1 100644 --- a/.github/workflows/lint-type-check-and-build.yaml +++ b/.github/workflows/lint-type-check-and-build.yaml @@ -21,6 +21,9 @@ jobs: cache: "yarn" - name: Setup .env file + # All the environment variables in .env.example are invalid, + # therefore the application will not be functional. But, it is enough + # for linting, type checking, and building. run: cat .env.example > .env - name: Install dependencies From 0a88535987bc19618c152fcbdf1b5bb3210578f4 Mon Sep 17 00:00:00 2001 From: Marciel Torres Date: Sat, 18 May 2024 14:25:47 -0300 Subject: [PATCH 07/20] Ajuste no texto --- src/app/about/page.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/app/about/page.tsx b/src/app/about/page.tsx index f4cd73d..c07cd8f 100644 --- a/src/app/about/page.tsx +++ b/src/app/about/page.tsx @@ -61,7 +61,7 @@ export default function About() { transformar um momento de crise em uma oportunidade para fazer a diferença na vida de um animal. Juntos, podemos salvar vidas e construir um futuro mais seguro para nossos amigos de quatro patas. - Além disso, esse projeto tem seu código fonte aberto e disponível para colaboração: + Além disso, esse projeto tem o código fonte aberto e disponível para colaboração: https://github.com/emiliosheinz/sos-pet

From 36c087ef45005e5ce5bb1de681fd989e6c2dcfc2 Mon Sep 17 00:00:00 2001 From: Emilio Heinzmann Date: Sat, 18 May 2024 16:15:23 -0300 Subject: [PATCH 08/20] fix: signIn word --- ...roviderButton.tsx => SignInProviderButtonn.tsx} | 6 +++--- src/app/signin/page.tsx | 14 +++++--------- src/server/auth.ts | 6 +++--- 3 files changed, 11 insertions(+), 15 deletions(-) rename src/app/signin/_components/{SigninProviderButton.tsx => SignInProviderButtonn.tsx} (86%) diff --git a/src/app/signin/_components/SigninProviderButton.tsx b/src/app/signin/_components/SignInProviderButtonn.tsx similarity index 86% rename from src/app/signin/_components/SigninProviderButton.tsx rename to src/app/signin/_components/SignInProviderButtonn.tsx index cea7aa3..67da59b 100644 --- a/src/app/signin/_components/SigninProviderButton.tsx +++ b/src/app/signin/_components/SignInProviderButtonn.tsx @@ -3,15 +3,15 @@ import { signIn } from "next-auth/react"; import Image from "next/image"; -type SigninProviderButtonProps = { +type SignInProviderButtonProps = { provider: { id: string; name: string }; callbackUrl: string; }; -export function SigninProviderButton({ +export function SignInProviderButton({ provider, callbackUrl, -}: SigninProviderButtonProps) { +}: SignInProviderButtonProps) { return ( + + + ); +} diff --git a/src/app/signin/_components/SignInProviderButton.tsx b/src/app/signin/_components/SignInProviderButton.tsx index 67da59b..60670c8 100644 --- a/src/app/signin/_components/SignInProviderButton.tsx +++ b/src/app/signin/_components/SignInProviderButton.tsx @@ -1,10 +1,10 @@ "use client"; -import { signIn } from "next-auth/react"; +import { type ClientSafeProvider, signIn } from "next-auth/react"; import Image from "next/image"; type SignInProviderButtonProps = { - provider: { id: string; name: string }; + provider: ClientSafeProvider; callbackUrl: string; }; @@ -15,7 +15,7 @@ export function SignInProviderButton({ return ( diff --git a/src/components/header/index.tsx b/src/components/header/index.tsx index e270b43..432dba3 100644 --- a/src/components/header/index.tsx +++ b/src/components/header/index.tsx @@ -2,32 +2,41 @@ import Image from "next/image"; import { Nav } from "./nav"; import { Sidebar } from "./sidebar"; import Link from "next/link"; +import { Button } from "../ui/button"; export function Header() { + const renderMainSection = () => ( +
+
+ + Logo + +
+
    +
  • + +
  • +
  • + +
  • +
+
+ ); + return (
-
+
-
-
- - Logo - -
-
    -
  • - Home -
  • -
  • - Sobre -
  • -
-
+ {renderMainSection()}
diff --git a/src/components/header/nav/index.tsx b/src/components/header/nav/index.tsx index 6ba732c..aaa56f6 100644 --- a/src/components/header/nav/index.tsx +++ b/src/components/header/nav/index.tsx @@ -14,39 +14,36 @@ import { import Link from "next/link"; import { User } from "../user"; -import { CiCircleChevDown } from "react-icons/ci"; - export function Nav() { const { data: session } = useSession(); - const router = useRouter(); return (