Rank 2: Process
import 'dart:core';import 'dart:convert';
import 'package:dart_appwrite/dart_appwrite.dart';
Client client = Client();Users users = Users(client);
Future<void> start(final req, final res) async { //wrap in big try catch as per stevens instructions try { // Init SDK print("instantiated the client and user");
final endpoint = req.variables['APPWRITE_FUNCTION_ENDPOINT'] ?? 'SECRET_KEY variable not found. You can set it in Function settings.';
final projectID = req.variables['FUNCTION_PROJECT_ID'] ?? 'PROJECT_ID variable not found. You can set it in Function settings.';
final apiKey = req.variables['APPWRITE_FUNCTION_API_KEY'] ?? 'API_KEY variable not found. You can set it in Function settings.';
print("set up Hooks"); print(endpoint); print(projectID); print(apiKey); print(req); print(res);
client .setEndpoint(endpoint) // Your API Endpoint .setProject(projectID) // Your project ID .setKey(apiKey) // Your secret API key ;
Map<String, dynamic> payload = jsonDecode(req); print(payload);
print("decoded payload: $payload");
String? name = payload["name"]; String? password = payload["password"]; String? email = payload["email"];
print("name: $name, password: $password, email: $email");
if (name == null password == null email == null) { res.json({"message": "Some fields are missing"}, status: 400); return; } await users.create( userId: ID.unique(), email: email, password: password, name: name, );
/*Future result = users.create( userId: ID.unique(), email: "test2@test.com", password: "testtest", name: "tester2", );*/ res.json({"message": "user created", "status": 200}); print("$name, $password, $email"); } on AppwriteException catch (e) { print(e.message); }}
Thank you so much Steven!
is this assertion based on my reading correct? (wanting to cover a few bases with these questions so please bear with me)