Back

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

  • 1
  • Functions
Matej
21 Jul, 2023, 12:29

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

TL;DR
The user was experiencing an issue where an anonymous user was being created even when a payload was present. The issue was that the payload in the console was being stringified twice, causing confusion. The solution was to remove the unnecessary stringification and escape characters from the payload. After making these adjustments, the issue was resolved and the user was able to continue working on their app.
Matej
21 Jul, 2023, 12:29

Yet this is the declaration of it

Matej
21 Jul, 2023, 12:30

Maybe that is the problem

Matej
21 Jul, 2023, 12:33

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

Matej
21 Jul, 2023, 12:34

From console logs

TypeScript
"{\"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\\\"}\""}```
Matej
21 Jul, 2023, 12:39

Idk why this is happening

Matej
21 Jul, 2023, 15:44

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

Matej
21 Jul, 2023, 16:46

These are my console log results

TypeScript
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

TypeScript
      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)
Matej
21 Jul, 2023, 16:49

So for some reason payload variables aren't fetched

Drake
21 Jul, 2023, 16:49

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

TypeScript
{"email": "user@example.com","password": "example","name": "User example"}
Matej
21 Jul, 2023, 16:52

This is parsed payload. While I am sending stringified and then parsing it - which is supposedly okay based on the console logs?

And I console.log parsed one, the one you wrote, and it doesn't return property values

Drake
21 Jul, 2023, 17:07

no you shouldn't be escaping stuff when putting it in the console

Drake
21 Jul, 2023, 17:08
Matej
21 Jul, 2023, 17:12

ok, so as I am going to be sending stringified payload from the client, then I can't test stringified payload via console 😦

Drake
21 Jul, 2023, 17:13

no, it's because in the console it's already a string...you're so you're stringifying it again by putting:

TypeScript
"{\"email\": \"user@example.com\",\"password\": \"example\",\"name\": \"User example\"}"
Matej
21 Jul, 2023, 17:21

I see now, that was really confusing, didn't know it was a string already as I didn't see any note about it. Thanks for helping out, it works fine now

Drake
21 Jul, 2023, 17:22

a note...like the example below?

Matej
21 Jul, 2023, 17:25

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

Drake
21 Jul, 2023, 17:25

did you look right under the input box for the custom data in the console?

Matej
21 Jul, 2023, 17:28

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

Drake
21 Jul, 2023, 17:29

if you put a stringified payload, your code would need to parse it twice

Matej
21 Jul, 2023, 17:29

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

Matej
21 Jul, 2023, 17:30

Yeah πŸ˜… Either way, it works now and I can continue working on my app πŸ˜„

Drake
21 Jul, 2023, 17:30
Drake
21 Jul, 2023, 17:30

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

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