Back

[Solved] How to properly create document on user creation

  • 0
  • Functions
fafa
20 Nov, 2023, 13:16

heyo,

How would I go towards making a document in a collection the moment a user gets created? I get the events part in the console, but how would that look like in the code?

Do I check every user and see if they all have a document? Does the event users.*.create send specific data to the function before it starts? like what user has been created?

TL;DR
There was a question about how to create a document in a collection when a user is created. The solution provided is to subscribe to the `users.*.create` event and use the whole user object as the payload in the function. The example function provided is in TypeScript and demonstrates how to access the properties of the user object. The user object properties can be found in the documentation.
WhiteWalker72
20 Nov, 2023, 15:25

When you subscribe to users.*.create the whole user object is passed to your function as the payload.

TypeScript
export default async ({ req, res, log, error }) => {
  const document = req.body as Models.User<{}>;
  log(document);
  
  // Your logic here
};

Here is an example function for you (TypeScript). These are the properties of the user: https://appwrite.io/docs/references/cloud/models/user

fafa
20 Nov, 2023, 15:55

Thank you! That really helps :)

fafa
20 Nov, 2023, 17:30

[Solved] How to properly create document on user creation

SylvainJack
22 Nov, 2023, 16:48

I am facing the same type of problem. I had my function working with older version of appwrite. But am having difficulty with new syntax.... am a beginner... The docs are complete but a bit complicated for me.

SylvainJack
22 Nov, 2023, 16:49

I am working with flutter / dart

SylvainJack
22 Nov, 2023, 16:50

When you say : with users.create event, the whole user object is passed as payload to the function... so I understand we have a way to recuperate all the info about the user... but how does the syntax work ?

fafa
22 Nov, 2023, 16:50

Please create a new support thread.

SylvainJack
22 Nov, 2023, 16:50

ah.. I thought it was better here since it's the same thing

SylvainJack
22 Nov, 2023, 16:50

sorry

fafa
22 Nov, 2023, 16:50

No worries :)

Reply

Reply to this thread by joining our Discord

Reply on Discord

Need support?

Join our Discord

Get community support by joining our Discord server.

Join Discord

Get premium support

Join Appwrite Pro and get email support from our team.

Learn more