Back

Account Deletion is not working

  • 0
  • Functions
  • Cloud
Brizi
15 Mar, 2025, 12:50

Hey There, i am trying to trigger a function with a swift ui button. The function ist to delete the currently active user with the userID, so that the account is deleted. The function is in the document. The error code, that always comes when i trigger the function, is this: 🔍 try to delete user with userId: correctUserId 📦 JSON-Payload: {"userId":"correctUserId"} ✅ Funktion succesfull! 📜 Status: failed 📄 Response: {"error":"User (role: guests) missing scope (users.write)"}. The API key i use has every rights activated. So does anybody know what the problem could be? Thank you very much for help 🙂

TL;DR
The developers are trying to delete a user account using an API endpoint, but they are encountering an error stating "User (role: guests) missing scope (users.write)." The issue might be related to the API key not having the necessary rights activated.
Brizi
15 Mar, 2025, 12:50

import sdk from 'node-appwrite';

export default async ({ req, res, log, error }) => { const client = new sdk.Client() .setEndpoint('https://cloud.appwrite.io/v1') // API Endpoint .setProject(process.env.APPWRITE_FUNCTION_PROJECT_ID) // Projekt-ID aus Umgebungsvariable .setKey(process.env.APPWRITE_API_KEY_DELETE); // Admin API Key

TypeScript
const users = new sdk.Users(client);

// userId aus der Anfrage holen
const { userId } = req.body;
if (!userId) {
    return res.json({ error: "userId ist erforderlich" }, 400);
}

try {
    await users.delete(userId);
    log(`✅ Benutzer ${userId} wurde erfolgreich gelöscht.`);
    return res.json({ success: `Benutzer ${userId} gelöscht.` });
} catch (err) {
    error(`❌ Fehler beim Löschen des Benutzers: ${err.message}`);
    return res.json({ error: err.message }, 500);
}

};

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