Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import 'package:dart_appwrite/dart_appwrite.dart';
- /*
- 'req' variable has:
- 'headers' - object with request headers
- 'payload' - request body data as a string
- 'variables' - object with function variables
- 'res' variable has:
- 'send(text, status: status)' - function to return text response. Status code defaults to 200
- 'json(obj, status: status)' - function to return JSON response. Status code defaults to 200
- If an error is thrown, a response with code 500 will be returned.
- */
- Future<void> start(final req, final res) async {
- final client = Client();
- // Uncomment the services you need, delete the ones you don't
- // final account = Account(client);
- // final avatars = Avatars(client);
- // final database = Databases(client);
- // final functions = Functions(client);
- // final health = Health(client);
- // final locale = Locale(client);
- // final storage = Storage(client);
- // final teams = Teams(client);
- // final users = Users(client);
- client
- .setEndpoint(req.variables['APPWRITE_FUNCTION_PROJECT_ID'])
- .setProject(req.variables['APPWRITE_FUNCTION_ENDPOINT'])
- .setKey(req.variables['APPWRITE_FUNCTION_API_KEY']);
- final users = Users(client);
- try {
- final userId =
- req.payload; // Assuming the userId is passed as the request payload
- await users.delete(userId: userId);
- res.json({'message': 'User deleted'});
- } catch (e) {
- res.send('Error deleting user: $e', status: 500);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment