Appwrite函數日誌中缺少JSON資料的顯示
P粉302160436
P粉302160436 2023-09-15 00:25:51
0
1
608

我使用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粉302160436
P粉302160436

全部回覆(1)
P粉463418483

您的所有使用者資料可能為空,因為您正在從$req['data']讀取,但輸入資料在$req['payload']中。

文檔說明如下:

有關更多信息,請參閱https://appwrite.io/docs/functions#writingYourOwnFunction

熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板