Hello Vercel Community,
I'm encountering a persistent issue with my Next.js application using Vercel KV for user registration. Despite following the documentation and implementing several debugging steps, I'm still unable to resolve this problem.
Issue: When attempting to register a new user, I receive a "Database operation failed" error. The client-side error message is:
Steps taken:
- Verified all required environment variables are set (KV_URL, KV_REST_API, KV_REST_API_TOKEN, KV_REST_API_READ_ONLY_TOKEN).
- Implemented detailed server-side logging in the registration API route.
- Created a debug endpoint to test Vercel KV connection.
- Checked Vercel logs for any error messages during registration attempts.
Relevant code:
Registration API route (app/api/auth/register/route.ts):
import { NextResponse } from "next/server"import { hash } from "bcryptjs"import { kv } from "@vercel/kv"export async function POST(request: Request) { console.log("Registration route called") try { const body = await request.json() console.log("Request body:", JSON.stringify(body)) const { name, company, email, password } = body if (!name || !company || !email || !password) { console.log("Missing required fields") return NextResponse.json({ message: "All fields are required" }, { status: 400 }) } try { console.log("Checking if user already exists") const existingUser = await kv.get(`user:${email}`) console.log("Existing user check result:", existingUser) if (existingUser) { console.log("Email already exists") return NextResponse.json({ message: "Email already registered" }, { status: 400 }) } console.log("Hashing password") const hashedPassword = await hash(password, 10)