Rank 3: Container
I"m having hard time doing a simple thing. I cannot get this to work. I found this example repo, https://github.com/Meldiron/almost-casino/ which was the only one showing how to create user related data on account creation, so I gave it a shot. I've edited the parts with sdk.Database(due the sdk api change) and added missing entries for db name.
const sdk = require("node-appwrite");
module.exports = async function (req, res) { // Init SDK
const client = new sdk.Client(); const databases = new sdk.Databases(client);
if ( !req.env['APPWRITE_FUNCTION_ENDPOINT'] || !req.env['APPWRITE_FUNCTION_PROJECT_ID'] || !req.env['APPWRITE_FUNCTION_USER_ID'] || !req.env['APPWRITE_FUNCTION_API_KEY'] ) { throw new Error("Missing environment variables."); } const userId = req.env['APPWRITE_FUNCTION_USER_ID']; console.log(userId, "thats my id");
const apiKey = req.env['APPWRITE_FUNCTION_API_KEY'] console.log(apiKey, "thats my api key")
const project = req.env["APPWRITE_FUNCTION_PROJECT_ID"] console.log(project, "that's my project")
const endpoint = req.env['APPWRITE_FUNCTION_ENDPOINT'] console.log(endpoint, "that's my endpoint")
client .setEndpoint(endpoint) .setProject(project) .setKey(apiKey);
let profile;
try { profile = await databases.getDocument('profiles', 'profiles', userId); } catch (err) { console.log(err, "User profile not found, trying to make one") profile = await databases.createDocument('profiles', 'profiles', userId, {balance: 500.0}); }
res.json({ profile });};I don't even see the console logs, just the error about Cannot read property APPWRITE_FUNCTION_ENDPOINT Any help would be appreciated, I have wasted 7 hours with this, and pretty much got stuck in an endless loop of doing the same thing over and over.
