StefanOriginal post
Web Developer
I'm having issues with querying User in node-appwrite. I've shared my codebase as well.
JavaScript
import { Account, Client, ID, Users } from "node-appwrite";
const APPWRITE_ENDPOINT = import.meta.env.VITE_APPWRITE_ENDPOINT;const APPWRITE_PROJECT_ID = import.meta.env.VITE_APPWRITE_PROJECT_ID;const APPWRITE_API_KEY = import.meta.env.VITE_APPWRITE_API_KEY;
const client = new Client() .setEndpoint(APPWRITE_ENDPOINT) .setProject(APPWRITE_PROJECT_ID) .setKey(APPWRITE_API_KEY);
export async function getUserByEmail(email: string) { const users = new Users(client);
// this is not appreciated way to filter users const response = await users.list(); const userIndex: number = response.users.findIndex((user) => user.email === email);
// if user email is not found on Users table if (userIndex !== -1) { return response.users[userIndex]; } else { return null; }}
export async function verifyUserEmail(email: string) { const account = new Account(client); await account.create(ID.unique(), email, "12345");}I tried to use Query in node-appwrite but every solutions and discussions didn't work for me.
Please let me know if someone has experienced with it.
Summary
- Developer is having trouble querying the `User` in `node-appwrite`.
- The `users.list()` method should accept an array of queries for filtering by email.
- Make sure to use the latest version of the Appwrite SDK (`v1.5.5`).
- The provided codebase reflects an outdated way of filtering users.
- Consider updating the code as per the instructions in the Appwrite documentation.
- Potential solution: Instead of querying all users and then finding the desired email, directly query users by email using `[Query.equal("email", email)]`.