Back

Project ID not found

  • 0
  • Auth
PirateKing
13 Jun, 2024, 03:16

I am getting this error while trying to use auth in appwrite: Project with the requested ID could not be found. Please check the value of the X-Appwrite-Project header to ensure the correct project ID is being used.

My code:

`export class AuthService { client = new Client(); account;

TypeScript
constructor() {
    this.client
        .setEndpoint(conf.appwriteUrl)
        .setProject(conf.appwriteProjectId);
    this.account = new Account(this.client);

}

async createAccount({ email, password, name }) {
    try {
        const userAccount = await this.account.create(ID.unique(), email, password, name);
        if (userAccount) {
            return this.login({ email, password });
        } else {
            return userAccount;
        }
    } catch (error) {
        throw error;
    }
}

async login({ email, password }) {
    try {
        return await this.account.createEmailSession(email, password);
    } catch (error) {
        throw error;
    }
}

async getCurrentUser() {
    try {
        return await this.account.get();
    } catch (error) {
        console.log("Appwrite serive :: getCurrentUser :: error", error);
    }

    return null;
}

async logout() {

    try {
        await this.account.deleteSessions();
    } catch (error) {
        console.log("Appwrite serive :: logout :: error", error);
    }
}

}

const authService = new AuthService();

export default authService`

I am doing const userData = await authService.createAccount(data) in another file to create account. Please forgive me if it is some trivial error as I am a newbie, also please dont delete this if it breaks any rule.

TL;DR
Error message: Project with the requested ID could not be found. Ensure the correct Project ID is used in the X-Appwrite-Project header when using auth in your appwrite project. Code issue correction: In the constructor of your `AuthService` class, pass the `conf.appwriteProjectId` when setting the project for the newly created Client instance. This should resolve the error.
Reply

Reply to this thread by joining our Discord

Reply on Discord

Need support?

Join our Discord

Get community support by joining our Discord server.

Join Discord

Get premium support

Join Appwrite Pro and get email support from our team.

Learn more