#[SOLVED] Appwrite function - anonymous user created even with payload present

28 messages · Page 1 of 1 (latest)

drowsy quarry
#
    if (req.payload) {
        const payload = JSON.parse(req.payload);
        console.log('PAYLOAD PARSED');
        console.log(payload);
        try {
            const promise = await users.create(node_appwrite_1.ID.unique(), payload.email, payload.password, payload.name);
            response.body = promise;
            response.statusCode = 200;
        }
        catch (error) {
            response.body = error;
        }
    }

This code creates anonymous user in my project for some reason.

Payload exists.

Stringified payload is sent from the function execution interface

"{\"email\": \"user@example.com\",\"password\": \"example\",\"name\": \"User example\"}"

Parsed payload is there as well that goes into the api request

{"email": "user@example.com","password": "example","name": "User example"}
#

Wondering if I missed anything again

drowsy quarry
#

Ah I see

#

I am using ID.unique() as I expected it will generate unique ID

#

Yet this is the declaration of it

#

Maybe that is the problem

#

Ok no that is not the issue, I still get anonymous users created

#

From console logs

"{\"email\": \"user@example.com\",\"password\": \"example\",\"name\": \"User example\"}"
PAYLOAD PARSED
{"email": "user@example.com","password": "example","name": "User example"}
USER_ID
6j4o3p1vi8eqtg6hrxag```

From function response 
```{"response":{"statusCode":200,"body":{"$id":"6j4o3p1vi8eqtg6hrxag","$createdAt":"2023-07-21T12:33:01.097+00:00","$updatedAt":"2023-07-21T12:33:01.097+00:00","name":"","password":"","hash":"argon2","hashOptions":{"memoryCost":2048,"timeCost":4,"threads":3},"registration":"2023-07-21T12:33:01.096+00:00","status":true,"passwordUpdate":"","email":"","phone":"","emailVerification":false,"phoneVerification":false,"prefs":[]}},"payload":"\"{\\\"email\\\": \\\"user@example.com\\\",\\\"password\\\": \\\"example\\\",\\\"name\\\": \\\"User example\\\"}\""}```
#

Idk why this is happening

drowsy quarry
#

I still can't figure out why is it creating anonymous user :x

drowsy quarry
#

These are my console log results

PAYLOAD UNPARSED
"{email: \"user@example.com\",\"password\": \"example\",\"name\": \"User example\"}"
PAYLOAD PARSED
{email: "user@example.com","password": "example","name": "User example"}
USER_ID
msm2ajmpvwn3nh7afdj0
USER_EMAIL

USER_PASSWORD

USER_NAME

These are my console logs

      const payload: IUser = JSON.parse(req.payload);
      console.log('PAYLOAD PARSED')
      console.log(payload)
      const userId = ID.custom(generateUniqueId());
      console.log('USER_ID')
      console.log(userId)
      console.log('USER_EMAIL')
      console.log(payload.email)
      console.log('USER_PASSWORD')
      console.log(payload.password)
      console.log('USER_NAME')
      console.log(payload.name)
#

So for some reason payload variables aren't fetched

dawn seal
# drowsy quarry

in here, don't escape/wrap with quotes. it should be:

{"email": "user@example.com","password": "example","name": "User example"}
drowsy quarry
dawn seal
drowsy quarry
dawn seal
drowsy quarry
drowsy quarry
#

Maybe this? Not sure if it would be helpful to have this note in the console as well. I missed it :X

dawn seal
drowsy quarry
#

Yes. But that also didn't indicate I can't really put stringified payload in there 🙂
And as I missed the docs I sent, took a while to figure out.

Another thing that might be good is interlinking appwrite console with the documentation.
But that would be to the UI people to decide, I can't really tell where would be good places to do that

dawn seal
drowsy quarry
#

Like placing links to docs, or making hover effect labels that would give more information about something in the console

drowsy quarry