Guest User

Untitled

a guest
May 17th, 2023
15
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.49 KB | None | 0 0
  1. import 'package:dart_appwrite/dart_appwrite.dart';
  2.  
  3. /*
  4. 'req' variable has:
  5. 'headers' - object with request headers
  6. 'payload' - request body data as a string
  7. 'variables' - object with function variables
  8.  
  9. 'res' variable has:
  10. 'send(text, status: status)' - function to return text response. Status code defaults to 200
  11. 'json(obj, status: status)' - function to return JSON response. Status code defaults to 200
  12.  
  13. If an error is thrown, a response with code 500 will be returned.
  14. */
  15.  
  16. Future<void> start(final req, final res) async {
  17. final client = Client();
  18.  
  19. // Uncomment the services you need, delete the ones you don't
  20. // final account = Account(client);
  21. // final avatars = Avatars(client);
  22. // final database = Databases(client);
  23. // final functions = Functions(client);
  24. // final health = Health(client);
  25. // final locale = Locale(client);
  26. // final storage = Storage(client);
  27. // final teams = Teams(client);
  28. // final users = Users(client);
  29.  
  30. client
  31. .setEndpoint(req.variables['APPWRITE_FUNCTION_PROJECT_ID'])
  32. .setProject(req.variables['APPWRITE_FUNCTION_ENDPOINT'])
  33. .setKey(req.variables['APPWRITE_FUNCTION_API_KEY']);
  34.  
  35. final users = Users(client);
  36.  
  37. try {
  38. final userId =
  39. req.payload; // Assuming the userId is passed as the request payload
  40. await users.delete(userId: userId);
  41. res.json({'message': 'User deleted'});
  42. } catch (e) {
  43. res.send('Error deleting user: $e', status: 500);
  44. }
  45. }
  46.  
Advertisement
Add Comment
Please, Sign In to add comment