首页  >  问答  >  正文

Appwrite函数日志中缺少JSON数据的显示

我使用php创建了一个函数来在Appwrite中创建新用户。 执行后,以下是输出:

  1. 响应:缺少必需的用户数据。
  2. 日志:没有记录日志
  3. 错误:没有记录错误
<?php

use Appwrite\Client;
use Appwrite\Services\Users;

require_once 'vendor/autoload.php';

return function ($req, $res) {
    $client = new Client();
    $users = new Users($client);

    if (
        !$req['variables']['APPWRITE_FUNCTION_ENDPOINT']
        || !$req['variables']['APPWRITE_FUNCTION_API_KEY']
        || !$req['variables']['APPWRITE_FUNCTION_PROJECT_ID']
    ) {
        return $res->send('环境变量未设置。函数无法使用Appwrite SDK。', 500);
    }

    $client
        ->setEndpoint($req['variables']['APPWRITE_FUNCTION_ENDPOINT'])
        ->setProject($req['variables']['APPWRITE_FUNCTION_PROJECT_ID'])
        ->setKey($req['variables']['APPWRITE_FUNCTION_API_KEY'])
        ->setSelfSigned(true);

    $userData = $req['data'] ?? [];

    $userId = $userData['userid'] ?? '';
    $name = $userData['name'] ?? '';
    $email = $userData['email'] ?? '';
    $password = $userData['password'] ?? '';

    if (empty($userId) || empty($name) || empty($email) || empty($password)) {
        return $res->send('缺少必需的用户数据。', 400);
    }

    $user = [
        'userid' => $userId,
        'name' => $name,
        'email' => $email,
        'password' => $password
    ];

    return $res->json(['user' => $user]);
};

P粉302160436P粉302160436423 天前597

全部回复(1)我来回复

  • P粉463418483

    P粉4634184832023-09-15 10:54:38

    您的所有用户数据可能为空,因为您正在从$req['data']读取,但输入数据在$req['payload']中。

    文档说明如下:

    有关更多信息,请参阅https://appwrite.io/docs/functions#writingYourOwnFunction

    回复
    0
  • 取消回复