#[SOLVED] Function to replicate created user not working

14 messages · Page 1 of 1 (latest)

lavish bolt
#

I'm trying to create a function that replicates a newly created user to a document in a collection(triggered by event)

I just get a Server Error occured trying to replicate the user: [email protected] in the logs.
I thought it might be an API permission scope issue, but I turned on all write permissions for the key and the error is still the same.

import { Client, Databases, Permission, Role } from 'node-appwrite';

export default async ({ req, res, log, error }) => {
  const client = new Client();

  client
    .setEndpoint(process.env.API_ENDPOINT)
    .setProject(process.env.PROJECT_ID)
    .setKey(process.env.APPWRITE_API_KEY);

  const databases = new Databases(client);

  const { $id, name, email } = req.body
  
  try {
    await databases.createDocument(process.env.DB_ID, process.env.COLLECTION_ID, $id, {
      name,
      email,
    }, 
    [
      Permission.read(Role.any()),   
      Permission.update(Role.user($id))
    ])
  } catch (e) {
    error(`Error: ${e} occurred trying to replicate the user: ${email}.`)
    return res.send("Error occurred");
  }

  return res.send("User created");
};

Any ideas?

lavish bolt
#

65fb2d87c9ad49a1ac50

lavish bolt
wicked magnet
wicked magnet
lavish bolt
wicked magnet
#

does it happen consistently?

#

are you sure your project id is set?

lavish bolt
wicked magnet
lavish bolt
slate kite