Back

[SOLVED] Cannot do Asynchronous Programming in a Function

  • 0
  • Functions
Aarush Acharya
7 Jul, 2023, 13:19

I have turned the default function to async but still even after using await the code does not wait at

TypeScript
otpData = await database.getDocument(//credentials) 
// as the code does not await this, the line below causes an error
// error:: connot read the otp of undefined
otp = otpData.data['otp']

Please do help how am I to tackle such a scenario

TL;DR
The user encountered an error when trying to perform asynchronous programming in a function. They mentioned that the problem is solved, but did not provide any specific solution. Another user suggested that the issue might be due to a `getDocument` function that returns data inside a `data` property. They recommended logging the `otpData` variable to verify the data structure. The user then shared an example code snippet showing how to await the `getDocument` function and access the `otp` value. The user is seeking further help on how to handle this scenario. Solution: It is recommended to ensure that the `getDocument` function is returning the
Binyamin
7 Jul, 2023, 13:50

I'm sure that getDocument returns the data inside data property. Try to logout the otpData variable to see what you're getting back.

From what I've seen it should be something like this.

TypeScript
otpData = await database.getDocument(//credentials) 

otp = otpData['otp']
Aarush Acharya
7 Jul, 2023, 14:15

Okay alright understood thanks

Aarush Acharya
7 Jul, 2023, 14:24

It worked

Aarush Acharya
7 Jul, 2023, 14:24

thanks a lot

Aarush Acharya
7 Jul, 2023, 14:25

apologies for not getting such a thing right

Aarush Acharya
7 Jul, 2023, 14:25

[SOLVED] Cannot do Asynchronous Programming in a Function

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