diff --git a/scripts/frontend-development/docker-compose.yaml b/scripts/frontend-development/docker-compose.yaml index 1127d35d..40ec7901 100644 --- a/scripts/frontend-development/docker-compose.yaml +++ b/scripts/frontend-development/docker-compose.yaml @@ -1,6 +1,7 @@ version: "3.7" services: + # This DB is for the FastAPI Backend. db: extends: file: ../backend-development/docker-compose.yaml @@ -10,6 +11,23 @@ services: interval: 2s timeout: 2s retries: 10 + + # This DB is for Web Authentication and data caching. + webdb: + image: postgres + restart: always + ports: + - 5433:5432 + environment: + POSTGRES_USER: postgres + POSTGRES_PASSWORD: postgres + healthcheck: + test: ["CMD", "pg_isready", "-U", "postgres"] + interval: 2s + timeout: 2s + retries: 10 + + # This lets you manually inspect the web and backend databases. adminer: extends: file: ../backend-development/docker-compose.yaml @@ -26,3 +44,15 @@ services: condition: service_healthy ports: - "8080:8080" + + # This fakes and SMTP email server. User registration emails can be found by going to + # localhost:1080 and opening the emails listed. + maildev: + image: maildev/maildev + restart: always + environment: + - MAILDEV_WEB_PORT=1080 + - MAILDEV_SMTP_PORT=1025 + ports: + - "1080:1080" + - "1025:1025" diff --git a/website/.env b/website/.env new file mode 100644 index 00000000..a95df390 --- /dev/null +++ b/website/.env @@ -0,0 +1,14 @@ +# The database created by running the jobs in /scripts/frontend-development/docker-compose.yaml +DATABASE_URL=postgres://postgres:postgres@localhost:5433/ocgpt_website + +# The FastAPI backend found by running the jobs in /scripts/frontend-development/docker-compose.yaml +FASTAPI_URL=http://localhost:8080 +FASTAPI_KEY=1234 + +# A dev Auth Secret. Can be exposed if we never use this publically. +NEXTAUTH_SECRET=O/M2uIbGj+lDD2oyNa8ax4jEOJqCPJzO53UbWShmq98= + +# The SMTP host and port found by running the jobs in /scripts/frontend-development/docker-compose.yaml +EMAIL_SERVER_HOST=localhost +EMAIL_SERVER_PORT=1025 +EMAIL_FROM=info@example.com diff --git a/website/.env.example b/website/.env.example deleted file mode 100644 index 1d7721c8..00000000 --- a/website/.env.example +++ /dev/null @@ -1,8 +0,0 @@ -FASTAPI_URL=http://xamla.com:8080 -FASTAPI_KEY=magic_key - -DISCORD_CLIENT_ID=your_discord_bot_client_id -DISCORD_CLIENT_SECRET=your_discord_bot_client_secret - -# Run "openssl rand -base64 32" to get this. -NEXTAUTH_SECRET=openssl_result diff --git a/website/.gitignore b/website/.gitignore index d61f5cb6..265e0054 100644 --- a/website/.gitignore +++ b/website/.gitignore @@ -26,7 +26,6 @@ yarn-error.log* .pnpm-debug.log* # local env files -.env .env*.local # vercel diff --git a/website/src/pages/api/auth/[...nextauth].ts b/website/src/pages/api/auth/[...nextauth].ts index 1798dc90..95bae8a2 100644 --- a/website/src/pages/api/auth/[...nextauth].ts +++ b/website/src/pages/api/auth/[...nextauth].ts @@ -5,16 +5,12 @@ import { PrismaAdapter } from "@next-auth/prisma-adapter"; import prisma from "src/lib/prismadb"; -export const authOptions = { - // Ensure we can store user data in a database. - adapter: PrismaAdapter(prisma), - providers: [ - // Register a Discord auth method. - DiscordProvider({ - clientId: process.env.DISCORD_CLIENT_ID, - clientSecret: process.env.DISCORD_CLIENT_SECRET, - }), - // Register an email magic link auth method. +const providers = []; + +console.log(process.env); +// Register an email magic link auth method. +if (process.env.NODE_ENV === "production") { + providers.push( EmailProvider({ server: { host: process.env.EMAIL_SERVER_HOST, @@ -25,8 +21,37 @@ export const authOptions = { }, }, from: process.env.EMAIL_FROM, - }), - ], + }) + ); +} else { + // Register an email magic link auth method. + providers.push( + EmailProvider({ + server: { + host: process.env.EMAIL_SERVER_HOST, + port: process.env.EMAIL_SERVER_PORT, + }, + from: process.env.EMAIL_FROM, + async generateVerificationToken() { + return "1234"; + }, + }) + ); +} + +if (process.env.DISCORD_CLIENT_ID) { + providers.push( + DiscordProvider({ + clientId: process.env.DISCORD_CLIENT_ID, + clientSecret: process.env.DISCORD_CLIENT_SECRET, + }) + ); +} + +export const authOptions = { + // Ensure we can store user data in a database. + adapter: PrismaAdapter(prisma), + providers, pages: { signIn: "/auth/signin", },