diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 0000000..e3a678d --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,14 @@ +{ + // Use IntelliSense to learn about possible attributes. + // Hover to view descriptions of existing attributes. + // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 + "version": "0.2.0", + "configurations": [ + { + "name": "Next.js: debug server-side", + "type": "node-terminal", + "request": "launch", + "command": "NODE_ENV=development next dev -p 3002 & local-ssl-proxy --config ./ssl-proxy.json" + } + ] +} diff --git a/src/app/(debug)/debug/page.tsx b/src/app/(debug)/debug/page.tsx index 683f5ef..f2070aa 100644 --- a/src/app/(debug)/debug/page.tsx +++ b/src/app/(debug)/debug/page.tsx @@ -1,10 +1,18 @@ import { SecureDebugDetails } from "@/components/debug/SecureDebugDetails"; +import React from "react"; +import HeadersPrinter from "@/components/debug/HeadersPrinter"; const DebugPage = async () => { return ( -
- {/* */} -
+ <> +

+ This is what we know +

+
+ + +
+ ); }; export default DebugPage; diff --git a/src/components/debug/HeadersPrinter.tsx b/src/components/debug/HeadersPrinter.tsx new file mode 100644 index 0000000..3fdc952 --- /dev/null +++ b/src/components/debug/HeadersPrinter.tsx @@ -0,0 +1,18 @@ +/* eslint-disable @typescript-eslint/no-unsafe-call */ +import React from "react"; +import { headers } from "next/headers"; +import { getRequestHeaders } from "@/lib/helpers/headers"; +import { Card, CardContent, CardHeader } from "@/components/ui/card"; + +const HeadersPrinter = () => { + const header = headers(); + + const request = getRequestHeaders(header); + return ( + + Request Headers + {request} + + ); +}; +export default HeadersPrinter; diff --git a/src/components/debug/SecureDebugDetails.tsx b/src/components/debug/SecureDebugDetails.tsx index 8de7f2a..4687cd0 100644 --- a/src/components/debug/SecureDebugDetails.tsx +++ b/src/components/debug/SecureDebugDetails.tsx @@ -7,11 +7,5 @@ import { headers } from "next/headers"; export const SecureDebugDetails = async () => { const session = await getServerSession(authOptions); const request = headers(); - return ( -
-
- -
-
- ); + return ; }; diff --git a/src/components/widgets/print-env.tsx b/src/components/widgets/print-env.tsx index 677aaf3..21b9023 100644 --- a/src/components/widgets/print-env.tsx +++ b/src/components/widgets/print-env.tsx @@ -11,7 +11,7 @@ type PrintEnvProps = { const PrintEnv: React.FC = ({ session, request }) => { return ( -
+
{session && ( Session diff --git a/src/env.js b/src/env.js index 4d57818..ade7aad 100644 --- a/src/env.js +++ b/src/env.js @@ -1,5 +1,5 @@ -import { createEnv } from "@t3-oss/env-nextjs"; -import { z } from "zod"; +import { createEnv } from '@t3-oss/env-nextjs'; +import { z } from 'zod'; export const env = createEnv({ /** @@ -11,14 +11,14 @@ export const env = createEnv({ .string() .url() .refine( - (str) => !str.includes("YOUR_PG_URL_HERE"), - "You forgot to change the default URL", + (str) => !str.includes('YOUR_PG_URL_HERE'), + 'You forgot to change the default URL', ), NODE_ENV: z - .enum(["development", "test", "production"]) - .default("development"), + .enum(['development', 'test', 'production']) + .default('development'), NEXTAUTH_SECRET: - process.env.NODE_ENV === "production" + process.env.NODE_ENV === 'production' ? z.string() : z.string().optional(), NEXTAUTH_URL: z.preprocess( @@ -30,6 +30,7 @@ export const env = createEnv({ ), GOOGLE_CLIENT_ID: z.string(), GOOGLE_CLIENT_SECRET: z.string(), + ALLOWED_DEBUG_IP: z.string().optional(), }, /** @@ -52,6 +53,7 @@ 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, + ALLOWED_DEBUG_IP: process.env.ALLOWED_DEBUG_IP, }, /** * Run `build` or `dev` with `SKIP_ENV_VALIDATION` to skip env validation. This is especially diff --git a/src/lib/helpers/headers.tsx b/src/lib/helpers/headers.tsx new file mode 100644 index 0000000..fe3ce3d --- /dev/null +++ b/src/lib/helpers/headers.tsx @@ -0,0 +1,16 @@ +import { type ReadonlyHeaders } from "next/dist/server/web/spec-extension/adapters/headers"; +import { type ReactElement } from "react"; + +export const getRequestHeaders = (headers: ReadonlyHeaders) => { + const result: ReactElement[] = []; + + for (const pair of headers.entries()) { + result.push( +
+ {pair[0]}: {pair[1]} +
, + ); + } + + return result; +};