see this data is passing
export const syncUserWithAppwrite = async (user) => {
const { id, username, emailAddresses } = user;
console.log("Syncing user with Appwrite:", id, username, emailAddresses[0].emailAddress);
try {
try {
// Try to fetch the document by user id
const existingUser = await databases.getDocument(
conf.databaseID,
conf.UsersCollectionID,
id
);
// If user exists, skip adding
if (existingUser) {
console.log('User already exists in Appwrite');
return; // or handle the case where user already exists
}
} catch (error) {
// Handle the case where the document does not exist
if (error.message.includes('Document not found')) {
// Add user to Appwrite if not exists
await databases.createDocument(conf.databaseID, conf.UsersCollectionID, {
userId: id,
username: username,
email: emailAddresses[0].emailAddress,
});
} else {
console.error('Error checking existing user:', error);
}
}
} catch (error) {
console.error("Error syncing user:", error);
}
};
for this function
but i tried to add the data manually to database then also not fetching