I'm encountering a persistent "Database not found" error in my Next.js application that uses Appwrite as the backend. Despite following the documentation and checking my configuration, I'm unable to resolve this issue. Below are the details: Environment:
Next.js (Version: [Your Next.js version]) Appwrite SDK (Version: [Your Appwrite SDK version]) Node.js (Version: [Your Node.js version])
Error Message: CopyAppwriteException: Database not found at _Client.call (webpack-internal:///(rsc)/./node_modules/node-appwrite/dist/client.mjs:283:13) ... code: 404, type: 'database_not_found', response: { message: 'Database not found', code: 404, type: 'database_not_found', version: '1.5.8' } Context: I'm trying to create a user document in my Appwrite database when a new user is created through a third-party authentication service (Dynamic). The error occurs when trying to execute the createDocument method of the Appwrite SDK.
Code Structure:
I have an appwrite.ts file that sets up the Appwrite client:
import { Client, Account, Databases, Users } from "node-appwrite";
export async function createAdminClient() { const client = new Client() .setEndpoint(process.env.NEXT_PUBLIC_APPWRITE_ENDPOINT!) .setProject(process.env.NEXT_PUBLIC_APPWRITE_PROJECT!) .setKey(process.env.NEXT_APPWRITE_KEY!);
return { database: new Databases(client), }; }
In my dynamic.user.actions.ts file, I have a createUser function:
const { APPWRITE_DATABASE_ID: DATABASE_ID, APPWRITE_USERS_COLLECTION_ID: USERS_COLLECTION_ID, APPWRITE_WALLETS_COLLECTION_ID: WALLETS_COLLECTION_ID, APPWRITE_VERIFIED_CREDENTIALS_COLLECTION_ID: VERIFIED_CREDENTIALS_COLLECTION_ID, } = process.env;
export const createUser = async (userData: CreateUserProps) => { try { const { database } = await createAdminClient(); console.log("New user data", userData);
const newUser = await database.createDocument(
DATABASE_ID,
USERS_COLLECTION_ID,
userData.id,
{
userId: userData.id,
email: userData.email,
// ... other user fields ...
}
);
// ... code to create related documents ...
return parseStringify(newUser);
} catch (error) { console.error("An error occurred while creating the user:", error); throw error; } };
Steps to Reproduce:
A new user signs up through the Dynamic authentication service. The webhook is triggered, calling my createUser function. The function attempts to create a new document in the Appwrite database. The "Database not found" error is thrown.
What I've Tried:
Triple-checked that the DATABASE_ID matches an existing database in my Appwrite project, as well with other env variables. Verified that the API key has the necessary permissions to access and modify the database. Verified permissions in each collection are set to All for all CRUD options. Tried hardcoding the database and collection IDs instead of using environment variables. Logged the database ID and other relevant information before the createDocument call and all variables are correctly passed.
Recommended threads
- Quota not resetting
hi, im using appwrite's free tier plani hit my read limts last month and the billing cycle said it would reset on june 4th but that is today, the billing cycle ...
- Request for temporary 3 to 4 hours datab...
Hi Appwrite Team, I hope you are doing well.We are an early-stage startup currently running on Appwrite Cloud. We have unfortunately exhausted our database rea...
- Realtime Error Invalid query: Syntax err...
I was test driving Self-Hosted Appwrite for my use with Swift IOS apps as a backend while back and after successful trials, I started to move to incorporate int...