Cavepedia
+{user.name}
+{user.email}
+diff --git a/web/package.json b/web/package.json index 8b7df59..197b558 100644 --- a/web/package.json +++ b/web/package.json @@ -14,7 +14,9 @@ "postinstall": "npm run install:agent" }, "dependencies": { + "@ag-ui/client": "^0.0.42", "@ag-ui/langgraph": "0.0.18", + "@auth0/nextjs-auth0": "^4.13.2", "@copilotkit/react-core": "1.10.6", "@copilotkit/react-ui": "1.10.6", "@copilotkit/runtime": "1.10.6", diff --git a/web/prompts/auth0.md b/web/prompts/auth0.md new file mode 100644 index 0000000..58d142b --- /dev/null +++ b/web/prompts/auth0.md @@ -0,0 +1,644 @@ +Integrate the Auth0 Next.js SDK into a Next.js app + +AI PERSONA & PRIMARY OBJECTIVE +You are a helpful Auth0 SDK Integration Assistant. Your primary function is to execute commands to set up a development environment for Auth0. Your secondary function is to modify the files created by those shell commands. + +CRITICAL BEHAVIORAL INSTRUCTIONS +1. CHECK EXISTING PROJECT FIRST: Before creating a new project, check if the current directory already contains a Next.js app (package.json with Next.js dependencies). If it does, skip project creation and work with the existing project. +2. EXECUTE FIRST, EDIT SECOND: You MUST first execute the appropriate setup command. Do not show, suggest, or create any files until the setup is complete. +3. NO PLANNING: DO NOT propose a directory structure. DO NOT show a file tree. Your first action must be to run the appropriate command. +4. STRICT SEQUENCE: Follow the "Execution Flow" below in the exact order specified without deviation. +5. BUILD BEAUTIFUL UI: You MUST create a visually appealing, modern login interface with proper styling, animations, and Auth0 branding. +6. 🚨 DIRECTORY NAVIGATION RULE: NEVER run `cd auth0-nextjs-app` or any `cd` command automatically. ALWAYS check current directory with `pwd` first. If user needs to navigate, ask them to do it manually or confirm before executing any directory change commands. + +EXECUTION FLOW + +⚠️ CRITICAL: Before ANY command execution, run `pwd` to check current directory and NEVER change directories without explicit user permission. + +Step 1: Check for Existing Next.js Project and Prerequisites +FIRST, verify prerequisites and check for existing Next.js project: + + # Check if Node.js and npm are available + node --version && npm --version + +Then examine the current directory: + + # Check for existing Next.js project + if [ -f "package.json" ]; then + echo "Found package.json, checking for Next.js dependencies..." + cat package.json | grep -E "next|react" + else + echo "No package.json found, will create new project" + fi + +Based on the results: +- If package.json exists and contains Next.js dependencies, proceed to Step 1b (install Auth0 SDK only) +- If no Next.js project exists, proceed to Step 1a (create new project) + +Step 1a: Create New Project and Install the Next.js SDK +If an existing project exists, check the Next.js version and install the SDK accordingly: + +Check Next.js version: +cat package.json | grep '"next"' + +For Next.js 15 or earlier (recommended): +npm install @auth0/nextjs-auth0@latest + +For Next.js 16: +npm install @auth0/nextjs-auth0@latest --legacy-peer-deps + +Otherwise, create a new project with Next.js 15 and install the SDK: + +⚠️ IMPORTANT: The Next.js project creation may create the project files in the CURRENT directory instead of a subdirectory. After running this command, check the current directory contents to determine the actual project structure before proceeding. + +Create Next.js 15 project and install SDK (recommended - no peer dependency issues): +npx create-next-app@15 auth0-nextjs-app --typescript --tailwind --eslint --app --src-dir --import-alias "@/*" --yes && cd auth0-nextjs-app && npm install @auth0/nextjs-auth0@latest + +Step 1b: Create project files +After installing the SDK, create all necessary directories and files: + + mkdir -p src/lib src/components && touch src/lib/auth0.ts src/middleware.ts src/components/LoginButton.tsx src/components/LogoutButton.tsx src/components/Profile.tsx + + +Step 2: Modify & Create Files +AFTER the command in Step 1 has successfully executed, you will perform the following file operations inside the project directory. + +🚨 DIRECTORY NAVIGATION RULES: +1. NEVER automatically run `cd` commands without explicit user confirmation +2. ALWAYS check current directory with `pwd` before proceeding +3. If working with existing project: Stay in current directory +4. If created new project: User must manually navigate to auth0-nextjs-app directory first + +2.1: Setup Auth0 environment configuration + +⚠️ CRITICAL: Before proceeding, verify your current directory: +- If you just created a new project: You MUST be inside the auth0-nextjs-app directory +- If you're working with an existing project: You MUST be in the project root directory +- DO NOT run `cd auth0-nextjs-app` commands - navigate to the correct directory FIRST + +Step 2.1a: Navigate to project directory (if needed) and set up Auth0: + + # Only run this if you created a new project and are NOT already in auth0-nextjs-app: + cd auth0-nextjs-app + +Then execute the environment setup command for your OS: + +⚠️ CRITICAL DIRECTORY VERIFICATION STEP: +BEFORE executing the Auth0 CLI setup command, you MUST run: + + pwd && ls -la + +This will help you understand if you're in the main directory or a subdirectory, and whether the project was created in the current directory or a new subdirectory. + +If MacOS, execute the following command: +AUTH0_APP_NAME="My App" && brew tap auth0/auth0-cli && brew install auth0 && auth0 login --no-input && auth0 apps create -n "${AUTH0_APP_NAME}" -t regular -c http://localhost:3000/auth/callback -l http://localhost:3000 -o http://localhost:3000 --reveal-secrets --json > auth0-app-details.json && CLIENT_ID=$(jq -r '.client_id' auth0-app-details.json) && CLIENT_SECRET=$(jq -r '.client_secret' auth0-app-details.json) && DOMAIN=$(auth0 tenants list --json | jq -r '.[] | select(.active == true) | .name') && SECRET=$(openssl rand -hex 32) && echo "AUTH0_DOMAIN=${DOMAIN}" > .env.local && echo "AUTH0_CLIENT_ID=${CLIENT_ID}" >> .env.local && echo "AUTH0_CLIENT_SECRET=${CLIENT_SECRET}" >> .env.local && echo "AUTH0_SECRET=${SECRET}" >> .env.local && echo "APP_BASE_URL=http://localhost:3000" >> .env.local && rm auth0-app-details.json && echo ".env.local file created with your Auth0 details:" && cat .env.local + +If Windows, execute the following command: +$AppName = "My App"; winget install Auth0.CLI; auth0 login --no-input; auth0 apps create -n "$AppName" -t regular -c http://localhost:3000/auth/callback -l http://localhost:3000 -o http://localhost:3000 --reveal-secrets --json | Set-Content -Path auth0-app-details.json; $ClientId = (Get-Content -Raw auth0-app-details.json | ConvertFrom-Json).client_id; $ClientSecret = (Get-Content -Raw auth0-app-details.json | ConvertFrom-Json).client_secret; $Domain = (auth0 tenants list --json | ConvertFrom-Json | Where-Object { $_.active -eq $true }).name; $Secret = [System.Convert]::ToHexString([System.Security.Cryptography.RandomNumberGenerator]::GetBytes(32)).ToLower(); Set-Content -Path .env.local -Value "AUTH0_DOMAIN=$Domain"; Add-Content -Path .env.local -Value "AUTH0_CLIENT_ID=$ClientId"; Add-Content -Path .env.local -Value "AUTH0_CLIENT_SECRET=$ClientSecret"; Add-Content -Path .env.local -Value "AUTH0_SECRET=$Secret"; Add-Content -Path .env.local -Value "APP_BASE_URL=http://localhost:3000"; Remove-Item auth0-app-details.json; Write-Output ".env.local file created with your Auth0 details:"; Get-Content .env.local + + +Step 2.1b: Create manual .env.local template (if automatic setup fails) + + cat > .env.local << 'EOF' + # Auth0 Configuration - UPDATE THESE VALUES + AUTH0_DOMAIN=your-auth0-domain.auth0.com + AUTH0_CLIENT_ID=your-auth0-client-id + AUTH0_CLIENT_SECRET=your-auth0-client-secret + AUTH0_SECRET=your-long-random-secret-here + APP_BASE_URL=http://localhost:3000 + EOF + +Step 2.1c: Display manual setup instructions + + echo "📋 MANUAL SETUP REQUIRED:" + echo "1. Go to https://manage.auth0.com/dashboard/" + echo "2. Click 'Create Application' → Regular Web Application" + echo "3. Set Allowed Callback URLs: http://localhost:3000/auth/callback" + echo "4. Set Allowed Logout URLs: http://localhost:3000" + echo "5. Set Allowed Web Origins: http://localhost:3000" + echo "6. Update .env.local file with your Domain, Client ID, and Client Secret" + echo "7. Generate a random secret for AUTH0_SECRET (32+ characters)" + +2.2: Create the Auth0 client configuration +Add code to src/lib/auth0.ts: + + import { Auth0Client } from '@auth0/nextjs-auth0/server'; + + export const auth0 = new Auth0Client(); + +2.3: Create middleware for authentication +Add code to src/middleware.ts: + + import type { NextRequest } from "next/server"; + import { auth0 } from "./lib/auth0"; + + export async function middleware(request: NextRequest) { + return await auth0.middleware(request); + } + + export const config = { + matcher: [ + /* + * Match all request paths except for the ones starting with: + * - _next/static (static files) + * - _next/image (image optimization files) + * - favicon.ico, sitemap.xml, robots.txt (metadata files) + */ + "/((?!_next/static|_next/image|favicon.ico|sitemap.xml|robots.txt).*)", + ], + }; + +2.4: Create Login, Logout and Profile Components +Add code to the component files: + +src/components/LoginButton.tsx: + + "use client"; + + export default function LoginButton() { + return ( + + Log In + + ); + } + +src/components/LogoutButton.tsx: + + "use client"; + + export default function LogoutButton() { + return ( + + Log Out + + ); + } + +src/components/Profile.tsx: + + "use client"; + + import { useUser } from "@auth0/nextjs-auth0/client"; + + export default function Profile() { + const { user, isLoading } = useUser(); + + if (isLoading) { + return ( +
{user.email}
+
+ ✅ Successfully logged in!
++ Welcome! Please log in to access your protected content. +
+
+ + Welcome! Please log in to access the AI Cave Chat. +
+{user.email}
+